IEqualityComparer Interface


定义用于支持比较对象是否相等的方法。Defines methods to support the comparison of objects for equality.

public interface class IEqualityComparer
public interface IEqualityComparer
public interface IEqualityComparer
type IEqualityComparer = interface
Public Interface IEqualityComparer


此接口允许实现集合的自定义相等性比较。This interface allows the implementation of customized equality comparison for collections. 也就是说,你可以创建你自己的相等性定义,并指定此定义与接受 IEqualityComparer 接口的集合类型一起使用。That is, you can create your own definition of equality, and specify that this definition be used with a collection type that accepts the IEqualityComparer interface. 在 .NET Framework 中,HashtableNameValueCollectionOrderedDictionary 集合类型的构造函数接受此接口。In the .NET Framework, constructors of the Hashtable, NameValueCollection, and OrderedDictionary collection types accept this interface.

有关此接口的泛型版本,请参阅 System.Collections.Generic.IEqualityComparer<T>For the generic version of this interface, see System.Collections.Generic.IEqualityComparer<T>.

IEqualityComparer 接口仅支持相等比较。The IEqualityComparer interface supports only equality comparisons. 排序和排序比较的自定义是由 IComparer 接口提供的。Customization of comparisons for sorting and ordering is provided by the IComparer interface.


Equals(Object, Object)

确定指定的对象是否相等。Determines whether the specified objects are equal.


返回指定对象的哈希代码。Returns a hash code for the specified object.

Applies to

See also