Mono Class Library: System.Collections.IComparer Overview | MembersSystem.Collections.IComparer.Compare Method |
Returns the sort order of two object instances. [Edit]
|
The return value is a negative number, zero, or a positive number reflecting the sort order of x as compared to y. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:
[Edit]
Value Condition A negative number x < y. Zero x == y. A positive number x > y.
Operation
For any objects A, B, and C, the following are required to be true:
IComparer.Compare(object, object) (A, A) is required to return zero.
If IComparer.Compare(object, object)(A, B) returns zero, then IComparer.Compare(object, object) (B, A) is required to return zero.
If IComparer.Compare(object, object)(A, B) returns zero and IComparer.Compare(object, object)(B, C) returns zero then IComparer.Compare(object, object) (A, C) is required to return zero.
If IComparer.Compare(object, object)(A, B) returns a value other than zero, then IComparer.Compare(object, object) (B, A) is required to return a value of the opposite sign.
If IComparer.Compare(object, object)(A, B) returns a value x not equal to zero, and IComparer.Compare(object, object)(B, C) returns a value y of the same sign as x, then IComparer.Compare(object, object) (A, C) is required to return a value of the same sign as x and y.
Note:The exact ordering of this method is unspecified. The intent of the method is to provide a mechanism that orders instances of a class in a manner that is consistent with the mathematical definitions of the relational operators (<, >, and ==), without regard for class-specific definitions of the operators.
Usage
This interface is used in conjunction with the Array.Sort(Array) and Array.BinarySearch(Array, object) methods.
[Edit]
Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0