Performs a case-sensitive comparison of two objects of the same type and returns a value indicating whether one is less than, equal to, or greater than the other.
A signed integer that indicates the relative values of a and b, as shown in the following table.
Less than zero a is less than b.
Zero a equals b.
Greater than zero a is greater than b.
Type Reason ArgumentException Both a and b are not null and do not implement the IComparable interface.
-or-
Both a and b are not null and are not assignment-compatible types.
If a implements IComparable, then a. CompareTo (b) is returned; otherwise, if b implements IComparable, then the negated result of b. CompareTo (a) is returned.
Comparing null with any type is allowed and does not generate an exception when using IComparable. When sorting, null is considered to be less than any other object.
String comparisons might have different results depending on the culture. For more information on culture-specific comparisons, see the System.Globalization namespace and Encoding and Localization.