System.Collections.Generic.EqualityComparer<T> Class

Provides a base class for implementations of the IEqualityComparer`1 generic interface.

See Also: EqualityComparer<T> Members


public abstract class EqualityComparer<T> : IEqualityComparer<T>, IEqualityComparer

Type Parameters

Documentation for this section has not yet been entered.


Derive from this class to provide a custom implementation of the IEqualityComparer`1 generic interface for use with collection classes such as the Dictionary`2 generic class, or with methods such as List`1.Sort(int, int, IComparer<`0>).

The EqualityComparer`1.Default property checks whether type T implements the IEquatable`1 generic interface and, if so, returns an EqualityComparer`1 that contains the implantation of the IEquatable`1.Equals(`0) method. Otherwise, it returns an EqualityComparer`1, as provided by T.

We recommend that you derive from the EqualityComparer`1 class instead of implementing the IEqualityComparer`1 interface, because the EqualityComparer`1 class tests for equality using the IEquatable`1.Equals(`0) method instead of the object.Equals(object) method. This is consistent with the Contains, IndexOf, LastIndexOf, and Remove methods of the Dictionary`2 class and other generic collections.


Namespace: System.Collections.Generic
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions:,
Since: .NET 2.0