Compare string with String.Compare(string str1, strng str2) : String Compare : String C# Examples


C# Examples » String » String Compare »

 

Compare string with String.Compare(string str1, strng str2)









    
using  System;  
  
class  MainClass  {  
    public  static  void  Main()  {  
        string  str1  =  "one";  
        string  str2  =  "two";  
  
        int  result  =  String.Compare(str1,  str2);  
        if(result  <  0)  
            Console.WriteLine(str1  +  "  is  less  than  "  +  str2);  
        else  if(result  >  0)  
            Console.WriteLine(str1  +  "  is  greater  than  "  +  str2);  
        else  
            Console.WriteLine(str1  +  "  equals  "  +  str2);  
    }  
}
    
   
  
   



Output

one is less than two


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo String
» String Compare