IEqualityComparer<T>.GetHashCode(T) 方法

定义

返回指定对象的哈希代码。Returns a hash code for the specified object.

public:
 int GetHashCode(T obj);
public int GetHashCode (T obj);
abstract member GetHashCode : 'T -> int
Public Function GetHashCode (obj As T) As Integer

参数

obj
T

Object,将为其返回哈希代码。The Object for which a hash code is to be returned.

返回

指定对象的哈希代码。A hash code for the specified object.

异常

obj 的类型为引用类型,objnullThe type of obj is a reference type and obj is null.

注解

实现此方法可以为类型T提供自定义的哈希代码,这对应于Equals方法提供的自定义相等性比较。Implement this method to provide a customized hash code for type T,corresponding to the customized equality comparison provided by the Equals method.

实施者说明

Equals(T, T)实现需要确保如果方法为两个对象x y GetHashCode(T)true返回,则的方法x返回的值必须等于为返回的值y.Implementations are required to ensure that if the Equals(T, T) method returns true for two objects x and y, then the value returned by the GetHashCode(T) method for x must equal the value returned for y.

适用于

另请参阅