harish reddy

harish reddy

  • 1.7k
  • 162
  • 12.7k

String compare result

Jan 22 2018 11:05 PM
string str1 = "COMPUTER";
string str2 = "computer";
string str;
int result;
Console.WriteLine();
Console.WriteLine("str1 = '{0}', str2 = '{1}'", str1, str2);
Console.WriteLine("Ignore case:");
result = string.Compare(str1, 2, str2, 2, 2, true);
str = ((result < 0) ? "less than" : ((result > 0) ? "greater than" : "equal to"));
Console.Write("Substring '{0}' in '{1}' is ", str1.Substring(2, 2), str1);
Console.Write("{0} ", str);
Console.WriteLine("substring '{0}' in '{1}'.", str2.Substring(2, 2), str2);
 
in above example, in this line result = string.Compare(str1, 2, str2, 2, 2, true);
why "true" is there? Also when i complie i am getting result as 0, result=0; 
pls let me know. 

Answers (3)