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.IEqualityComparer替换是或System.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.GetHashCode重写和Object.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.

适用于

另请参阅