mscorlib 2.0.0.0 4.0.0.0 Contravariant To be added.

This interface is implemented by types whose values can be ordered, primarily for sorting. For example, one number can be larger than a second number, and one string can appear in alphabetical order before another. A value type or class implements the method to create a type-specific comparison method suitable for purposes such as sorting.

The interface defines the method, which determines the sort order of instances of the implementing type. The interface defines the method, which determines the equality of instances of the implementing type.

The implementation of the method must return an that has one of three values, as shown in the following table.

Value

Meaning

Less than zero

This object is less than the object specified by the method.

Zero

This object is equal to the method parameter.

Greater than zero

This object is greater than the method parameter.

The interface provides a strongly typed comparison method for ordering members of a generic collection object. Because of this, it is usually not called directly from developer code. Instead, it is called automatically by methods such as and .

Defines a generalized comparison method that a value type or class implements to create a type-specific comparison method for ordering instances.

- Method
  2.0.0.0
  4.0.0.0
  System.Int32 `` To be added.

  Returns the sort order of the current instance compared to the specified object.

  A value that reflects the sort order of the current instance as compared to . The following table defines the conditions under which the returned value is a negative number, zero, or a positive number.

  Returned Value
  Description
  A negative value
  The current instance is < .
  Zero
  The current instance is == .
  A positive value
  The current instance is > than .

  For any objects A, B and C, the following are required to be true:

  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) is zero, then B.CompareTo(C) and A.CompareTo(C) must have the same sign (negative, zero or positive).

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

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

  Use the method to determine the ordering of instances of a class.