Updated: September 2009
Defines a generalized method that a value type or class implements to create a type-specific method for determining equality of instances.
Assembly: mscorlib (in mscorlib.dll)
This interface is implemented by types whose values can be equated (for example, the numeric and string classes). A value type or class implements the Equals method to create a type-specific method suitable for determining equality of instances.
The IComparable<T> interface defines the CompareTo method, which determines the sort order of instances of the implementing type. The interface defines the Equals method, which determines the equality of instances of the implementing type.
The interface is used by generic collection objects such as Dictionary<TKey, TValue>, List<T>, and LinkedList<T> when testing for equality in such methods as Contains, IndexOf, LastIndexOf, and Remove. It should be implemented for any object that might be stored in a generic collection.
Implement the IComparable<T> interface only if you want to define your own definition for equality for a type. Otherwise, the default reference equality (the Equals method) will work for reference types.
The interface defines the equality on the type itself, whereas an IEqualityComparer<T> interface is external to the type and enables many different implementations to be used for the same type.Notes to Implementers:
Replace the type parameter of the interface with the type that is implementing this interface.
If you implement , you should also override the base class implementations of Object::Equals(Object) and GetHashCode so that their behavior is consistent with that of the IEquatable<T>::Equals method. If you do override Object::Equals(Object), your overridden implementation is also called in calls to the static Equals(System.Object, System.Object) method on your class. This ensures that all invocations of the Equals method return consistent results.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.