System.Collections.Generic.IEqualityComparer<T>

Defines methods to support the comparison of objects for equality.

See Also: IEqualityComparer<T> Members

Syntax

public interface IEqualityComparer<T>

Type Parameters

T
Documentation for this section has not yet been entered.

Remarks

This interface allows the implementation of customized equality comparison for collections. That is, you can create your own definition of equality for type T, and specify that this definition be used with a collection type that accepts the IEqualityComparer`1 generic interface. In the .NET Framework, constructors of the Dictionary`2 generic collection type accept this interface.

A default implementation of this interface is provided by the EqualityComparer`1.Default property of the EqualityComparer`1 generic class. The StringComparer class implements IEqualityComparer`1 of type string.

This interface supports only equality comparisons. Customization of comparisons for sorting and ordering is provided by the IComparer`1 generic interface.

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.

Requirements

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