public interface IComparable
|
A value type or class implements the IComparable.CompareTo method to create a type-specific comparison method suitable for purposes such as sorting.
CompareTo | Compares the current instance with another object of the same type. |
obj
Value | Meaning |
---|---|
Less than zero | This instance is less than . |
Zero | This instance is equal to . |
Greater than zero | This instance is greater than . |
Exception Type | Condition |
---|---|
ArgumentException | obj is not the same type as this instance. |
By definition, any object compares greater than null; and two null references compare equal to each other.
The parameter, obj, must be the same type as the class or value type that implements this interface; otherwise, an ArgumentException is thrown.
A.CompareTo(A)
is required to return zero.
If
A.CompareTo(B)
returns zero then
B.CompareTo(A)
is required to return zero.
If
A.CompareTo(B)
returns zero and
B.CompareTo(C)
returns zero then
A.CompareTo(C)
is required to return zero.
If
A.CompareTo(B)
returns a value other than zero then
B.CompareTo(A)
is required to return a value of the opposite sign.
If
A.CompareTo(B)
returns a value x not equal to zero, and
B.CompareTo(C)
returns a value y of the same sign as x, then
A.CompareTo(C)
is required to return a value of the same sign as x and y.