Description: CompareTo method is used to compare the current instance with another object of the same type. It returns an integer that indicates the relationship between the two objects, which can be less than zero, equal to zero, or greater than zero.
Examples: 1. Comparing strings: string str1 = "hello"; string str2 = "world"; int result = str1.CompareTo(str2); // result will be less than zero because "hello" is less than "world" alphabetically.
2. Comparing integers: int num1 = 10; int num2 = 5; int result = num1.CompareTo(num2); // result will be greater than zero because 10 is greater than 5.
Package library: CompareTo method is a part of .NET Framework Class Library, specifically System.IComparable interface. It is included in the System namespace.
C# (CSharp) this.CompareTo - 30 examples found. These are the top rated real world C# (CSharp) examples of this.CompareTo extracted from open source projects. You can rate examples to help us improve the quality of examples.