IHashCodeProvider 介面

定義

警告

Please use IEqualityComparer instead.

使用自訂雜湊函式,提供物件的雜湊程式碼。Supplies a hash code for an object, using a custom hash function.

public interface class IHashCodeProvider
[System.Obsolete("Please use IEqualityComparer instead.")]
public interface IHashCodeProvider
public interface IHashCodeProvider
[System.Obsolete("Please use IEqualityComparer instead.")]
[System.Runtime.InteropServices.ComVisible(true)]
public interface IHashCodeProvider
[<System.Obsolete("Please use IEqualityComparer instead.")>]
type IHashCodeProvider = interface
type IHashCodeProvider = interface
[<System.Obsolete("Please use IEqualityComparer instead.")>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type IHashCodeProvider = interface
Public Interface IHashCodeProvider
衍生
屬性

備註

重要

我們不建議您將介面用於 IHashCodeProvider 新的開發。We don't recommend that you use the IHashCodeProvider interface for new development. 其建議的取代為 System.Collections.IEqualityComparerSystem.Collections.Generic.IEqualityComparer<T> 介面。Its recommended replacement is the System.Collections.IEqualityComparer or System.Collections.Generic.IEqualityComparer<T> interface.

IHashCodeProvider介面會與類別搭配使用 HashtableThe IHashCodeProvider interface is used in conjunction with the Hashtable class. 物件用來做為索引鍵的物件 Hashtable 必須覆寫 Object.GetHashCodeObject.Equals 方法。The objects used as keys by a Hashtable object must override the Object.GetHashCode and Object.Equals methods. Object.GetHashCode 或金鑰的實 Object.GetHashCode 作為雜湊碼提供者使用。Object.GetHashCode or the key's implementation of Object.GetHashCode is used as the hash code provider. Object.Equals 或索引鍵的實 Object.Equals 作為比較子使用。Object.Equals or the key's implementation of Object.Equals is used as the comparer.

不過,某些函式的多載 Hashtable 會採用實作為的參數 IHashCodeProvider 或實作為的參數 IComparerHowever, some overloads of the Hashtable constructor take a parameter that is an IHashCodeProvider implementation, or a parameter that is an IComparer implementation, or both. 如果將 IHashCodeProvider 實值傳遞至函式,則 IHashCodeProvider.GetHashCode 會使用該實作為雜湊碼提供者的方法。If an IHashCodeProvider implementation is passed to the constructor, the IHashCodeProvider.GetHashCode method of that implementation is used as the hash code provider. 如果將 IComparer 實作為傳遞至函式,則 IComparer.Compare 會使用該實作為比較子的方法。If an IComparer implementation is passed to the constructor, the IComparer.Compare method of that implementation is used as the comparer.

方法

GetHashCode(Object)

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

適用於

另請參閱