mscorlib 2.0.0.0 4.0.0.0 Contravariant To be added.

This interface is used with the and methods. It provides a way to customize the sort order of a collection. Classes that implement this interface include the and generic classes.

The default implementation of this interface is the class. The class implements this interface for type .

This interface supports ordering comparisons. That is, when the method returns 0, it means that two objects sort the same. Implementation of exact equality comparisons is provided by the generic interface.

We recommend that you derive from the class instead of implementing the interface, because the class provides an explicit interface implementation of the method and the property that gets the default comparer for the object.

Defines a method that a type implements to compare two objects.

- Method
  2.0.0.0
  4.0.0.0
  System.Int32 `` `` First to compare. Second to compare.

  Returns the sort order of two instances.

  A containing a value that reflects the sort order of as compared to . 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
  < .
  Zero
  == .
  A positive number
  > .

  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 not equal to zero, and Compare(B,C) returns a value of the same sign as , then Compare(A,C) is required to a value of the same sign as and .

  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.