Compare Two String Using Compare Method in C#

  1. string str1 = "my string";  
  2. string str2 = "This is not my string";  
  3. if(String.Compare(str1,str2) < 0)  
  4. {  
  5.    // str1 is less than str2  
  6.    Console.WriteLine("Yes");  
  7. }  
  8. else if(String.Compare(str1,str2) == 0)  
  9. {  
  10.    // str1 equals str2  
  11.    Console.WriteLine("Equals");  
  12. }  
  13. else  
  14. {  
  15.    // str11 is greater than str2, and String.Compare returned a value greater than 0  
  16.    Console.WriteLine("No");  
  17. }