IHashCodeProvider 接口

定义

警告

此 API 现已过时。

使用自定义哈希函数为对象提供哈希代码。Supplies a hash code for an object, using a custom hash function.

public interface class 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.

适用于

另请参阅