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方法針對兩個物件GetHashCode(T) xy傳回,則的方法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.

適用於

另請參閱