IEqualityComparer 介面

定義

定義支援物件之相等比較的方法。Defines methods to support the comparison of objects for equality.

public interface class IEqualityComparer
[System.Runtime.InteropServices.ComVisible(true)]
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 Hashtable中,、 NameValueCollectionOrderedDictionary集合類型的函式會接受此介面。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.

GetHashCode(Object)

傳回指定物件的雜湊碼。Returns a hash code for the specified object.

適用於

另請參閱