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

要傳回雜湊碼的 ObjectThe Object for which a hash code is to be returned.

傳回

Int32

指定物件的雜湊碼。A hash code for the specified object.

例外狀況

obj 的型別是參考型別,而 objnullThe type of obj is a reference type and obj is null.

備註

請執行此方法,以提供類型的自訂雜湊碼 T ,對應至方法所提供的自訂相等比較 EqualsImplement 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) 方法 true 傳回兩個物件 xy ,則方法所傳回的值 GetHashCode(T) x 必須等於傳回的值 yImplementations 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.

適用於

另請參閱