find and solve || findandsolve.com
Please wait.....

C# String CompareTo Method

In the  C# CompareTo() method is used to compare String instance with a specified String object and It indicates whether this String instance precedes, follows, or appears in the same position in the sort order as the specified object or String.


Syntax

public int CompareTo(string strPar)  

public int CompareTo(Object)  
Parameters

strPar: it is a string argument which is used to compare

Return

It returns an integer value.

C# String CompareTo() Method Example


Example
    using System;    
    public class StringCmopareToExample
    {         public static void Main(string[] args)
        {
            string str = "HelloWord";
            string str1 = "helloWord";
            string str2 = "csharp";
            Console.WriteLine(str.CompareTo(str1));
            Console.WriteLine(str2.CompareTo(str2));
        }
    }    
output
1
0