IEqualityComparer<T>.GetHashCode(T) IEqualityComparer<T>.GetHashCode(T) IEqualityComparer<T>.GetHashCode(T) IEqualityComparer<T>.GetHashCode(T) Method

定義

傳回指定物件的雜湊碼。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

要傳回雜湊碼的 ObjectThe 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)方法會傳回true兩個物件xy,然後將所傳回的值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.

適用於

另請參閱