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