IHashCodeProvider 介面

定義

警告

此 API 現已淘汰。

使用自訂雜湊函式,提供物件的雜湊程式碼。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
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 介面會與 Hashtable 類別搭配使用。The 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 執行的參數,或是 IComparer 實作為或兩者的參數。However, 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.

適用於

另請參閱