C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C# String CompareTo()The C# CompareTo() method is used to compare String instance with a specified String object. It indicates whether this String instance precedes, follows, or appears in the same position in the sort order as the specified string or not. Signaturepublic int CompareTo(String str) public int CompareTo(Object) Parametersstr: it is a string argument which is used to compare. ReturnIt returns an integer value. C# String CompareTo() Method Exampleusing System; public class StringExample { public static void Main(string[] args) { string s1 = "hello"; string s2 = "hello"; string s3 = "csharp"; Console.WriteLine(s1.CompareTo(s2)); Console.WriteLine(s2.CompareTo(s3)); } } Output: 0 1
Next TopicC# String Concat()
|