Condividi tramite


IEqualityComparer<T> Interface

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Defines methods to support the comparison of objects for equality.

Namespace:  System.Collections.Generic
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Interface IEqualityComparer(Of In T)
public interface IEqualityComparer<in T>

Type Parameters

  • inT
    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 IEqualityComparer<T> type exposes the following members.

Methods

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Equals Determines whether the specified objects are equal.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetHashCode Returns a hash code for the specified object.

Top

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<T> generic interface. In the .NET Framework, constructors of the Dictionary<TKey, TValue> generic collection type accept this interface.

A default implementation of this interface is provided by the Default property of the EqualityComparer<T> generic class. The StringComparer class implements IEqualityComparer<T> of type String.

This interface supports only equality comparisons. Customization of comparisons for sorting and ordering is provided by the IComparer<T> generic interface.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.