IEqualityComparer<T>.GetHashCode(T) Method

Definition

返回指定对象的哈希代码。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

Parameters

obj
T

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

Returns

Int32

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

Exceptions

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

Remarks

实现此方法可为类型 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.

Notes to Implementers

若要确保 Equals(T, T) 方法返回 xy两个对象的 true,则需要实现,然后 GetHashCode(T) 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.

Applies to

See also