IComparable<T> Interface
Defines a generalized comparison method that a value type or class implements to create a type-specific comparison method for ordering instances.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Type Parameters
- in T
The type of objects to compare.
This type parameter is contravariant. That is, you can use either the type you specified or any type that is less derived. For more information about covariance and contravariance, see 2678dc63-c7f9-4590-9ddc-0a4df684d42e.
The IComparable<T> type exposes the following members.
This interface is implemented by types whose values can be ordered; for example, the numeric and string classes. A value type or class implements the CompareTo method to create a type-specific comparison method suitable for purposes such as sorting.
Note: |
|---|
The IComparable<T> interface defines the CompareTo method, which determines the sort order of instances of the implementing type. The IEquatable<T> interface defines the Equals method, which determines the equality of instances of the implementing type. |
The IComparable<T> 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 sorting methods such as the List<T>::Sort() method.
Notes to ImplementersReplace the type parameter of the IComparable<T> interface with the type that is implementing this interface.
The following code example illustrates the implementation of IComparable for a simple Temperature object.
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

