public interface IComparer<T>

mscorlib

BCL

Provides a mechanism to customize comparison in sort ordering of a generic collection.

System.Collections.Generic Namespace

IComparer<T> Methods

int Compare(T x, T y)

Returns the sort order of two`T`

instances.

- x
- First
`T`

to compare.- y
- Second
`T`

to compare.

A Int32 containing a value that reflects the sort order ofxas compared toy. The following table defines the conditions under which the returned value is a negative number, zero, or a positive number.

Value Condition A negative number x<y.Zero x==y.A positive number x>y.

[Behaviors: For any objects A, B and C, the following are required to be true:Compare(A,A) is required to return zero.

If Compare(A,B) returns zero then Compare(B,A) is required to return zero.

If Compare(A,B) is zero, then Compare(B,C) and Compare(A,C) must have the same sign (negative, zero or positive).

If Compare(B,C) is zero, then Compare(A,B) and Compare(A,C) must have the same sign (negative, zero or positive).

If Compare(A,B) returns zero and Compare(B,C) returns zero then Compare(A,C) is required to return zero.

If Compare(A,B) returns a value other than zero then Compare(B,A) is required to return a value of the opposite sign.

If Compare(A,B) returns a value

xnot equal to zero, and Compare(B,C) returns a valueyof the same sign asx, then Compare(A,C) is required to a value of the same sign asxandy.The exact behavior of this method is unspecified. The intent of this 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.

]

System.Collections.Generic.IComparer<T> Interface, System.Collections.Generic Namespace