Write a C# Sharp program to compare the current string instance with another string
- برمجة سي شارب
- برمجة
- 2021-05-30
- ahmadghneem
الأجوبة
using System;
public class Example33
{
public static void Main()
{
string str1 = "Goodbye";
string str2 = "Hello";
string str3 = "a small string";
string str4 = "goodbye";
// Compare a string to itself.
Console.WriteLine(CompareStrings(str1, str1));
Console.WriteLine(CompareStrings(str1, str2));
Console.WriteLine(CompareStrings(str1, str3));
// Compare a string to another string that varies only by case.
Console.WriteLine(CompareStrings(str1, str4));
Console.WriteLine(CompareStrings(str4, str1));
}
private static string CompareStrings( string str1, string str2 )
{
// Compare the values, using the CompareTo method on the first string.
int cmpVal = str1.CompareTo(str2);
if (cmpVal == 0) // The strings are the same.
return "The strings occur in the same position in the sort order.";
else if (cmpVal > 0)
return "The first string precedes the second in the sort order.";
else
return "The first string follows the second in the sort order.";
}
}أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال