Provides a base class for implementations of the IEqualityComparer<T> generic interface.
Assembly: mscorlib (in mscorlib.dll)
Thetype exposes the following members.
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Equals(T, T)||When overridden in a derived class, determines whether two objects of type T are equal.|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetHashCode()||Serves as the default hash function. (Inherited from Object.)|
|GetHashCode(T)||When overridden in a derived class, serves as a hash function for the specified object for hashing algorithms and data structures, such as a hash table.|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
Derive from this class to provide a custom implementation of the IEqualityComparer<T> generic interface for use with collection classes such as the Dictionary<TKey, TValue> generic class, or with methods such as List<T>::Sort.
The Default property checks whether type T implements the System::IEquatable<T> generic interface and, if so, returns an that invokes the implementation of the IEquatable<T>::Equals method. Otherwise, it returns an , as provided by T.
We recommend that you derive from the class instead of implementing the IEqualityComparer<T> interface, because the class tests for equality using the IEquatable<T>::Equals method instead of the Object::Equals method. This is consistent with the Contains, IndexOf, LastIndexOf, and Remove methods of the Dictionary<TKey, TValue> class and other generic collections.
The following example creates a dictionary collection of objects of type Box with an equality comparer. Two boxes are considered equal if their dimensions are the same. It then adds the boxes to the collection.
The dictionary is recreated with an equality comparer that defines equality in a different way: Two boxes are considered equal if their volumes are the same.
.NET FrameworkSupported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
XNA FrameworkSupported in: 3.0, 2.0, 1.0
Portable Class LibrarySupported in: Portable Class Library
Supported in: Windows Phone 8.1
Supported in: Windows Phone Silverlight 8.1
Supported in: Windows Phone Silverlight 8