StringComparer.GetHashCode 方法

定義

以衍生類別覆寫時,取得目前 StringComparer 物件的雜湊碼。When overridden in a derived class, gets the hash code for the current StringComparer object.

多載

GetHashCode(Object)

以衍生類別覆寫時,取得指定之物件的雜湊碼。When overridden in a derived class, gets the hash code for the specified object.

GetHashCode(String)

以衍生類別覆寫時,取得指定之字串的雜湊碼。When overridden in a derived class, gets the hash code for the specified string.

GetHashCode(Object)

以衍生類別覆寫時,取得指定之物件的雜湊碼。When overridden in a derived class, gets the hash code for the specified object.

public:
 virtual int GetHashCode(System::Object ^ obj);
public int GetHashCode (object obj);
override this.GetHashCode : obj -> int
Public Function GetHashCode (obj As Object) As Integer

參數

obj
Object

物件。An object.

傳回

obj 參數值計算之 32 位元帶正負號的雜湊碼。A 32-bit signed hash code calculated from the value of the obj parameter.

實作

例外狀況

可用的記憶體不足,無法配置運算雜湊碼所需的緩衝區。Not enough memory is available to allocate the buffer that is required to compute the hash code.

objnullobj is null.

備註

方法比方法更有效率,因為obj參數不需要取消裝箱來執行作業。 GetHashCode GetHashCode(String)The GetHashCode(String) method is more efficient than the GetHashCode method because the obj parameter does not have to be unboxed to perform the operation.

方法會配置與obj大小成正比的記憶體數量,以obj計算的雜湊碼。 GetHashCode(Object)The GetHashCode(Object) method allocates an amount of memory that is proportional to the size of obj to calculate the hash code of obj. 如果是大型字串,嘗試取得雜湊碼可能會擲ArgumentException回。In the case of large strings, trying to retrieve the hash code can throw an ArgumentException. 相反地,您可以使用替代演算法,在計算雜湊碼時配置固定的記憶體數量。Instead, you can use an alternate algorithm that allocates a fixed amount of memory when calculating hash codes. 若要使用此演算法,請將< NetFx45_CultureAwareComparerGetHashCode_LongStrings >元素新增至應用程式佈建檔的 <執行時間 >區段。To use this algorithm, add the <NetFx45_CultureAwareComparerGetHashCode_LongStrings> element to the <runtime> section of your application's configuration file.

GetHashCode(String)

以衍生類別覆寫時,取得指定之字串的雜湊碼。When overridden in a derived class, gets the hash code for the specified string.

public:
 abstract int GetHashCode(System::String ^ obj);
public abstract int GetHashCode (string obj);
override this.GetHashCode : string -> int
Public MustOverride Function GetHashCode (obj As String) As Integer

參數

obj
String

字串。A string.

傳回

obj 參數值計算之 32 位元帶正負號的雜湊碼。A 32-bit signed hash code calculated from the value of the obj parameter.

實作

例外狀況

可用的記憶體不足,無法配置運算雜湊碼所需的緩衝區。Not enough memory is available to allocate the buffer that is required to compute the hash code.

objnullobj is null.

備註

方法比方法更有效率,因為obj參數不需要取消裝箱來執行作業。 GetHashCode(Object) GetHashCode(String)The GetHashCode(String) method is more efficient than the GetHashCode(Object) method because the obj parameter does not have to be unboxed to perform the operation.

方法會配置與obj大小成正比的記憶體數量,以obj計算的雜湊碼。 GetHashCode(String)The GetHashCode(String) method allocates an amount of memory that is proportional to the size of obj to calculate the hash code of obj. 如果是大型字串,嘗試取得雜湊碼可能會擲ArgumentException回。In the case of large strings, trying to retrieve the hash code can throw an ArgumentException. 相反地,您可以使用替代演算法,在計算雜湊碼時配置固定的記憶體數量。Instead, you can use an alternate algorithm that allocates a fixed amount of memory when calculating hash codes. 若要使用此演算法,請將< NetFx45_CultureAwareComparerGetHashCode_LongStrings >元素新增至應用程式佈建檔的 <執行時間 >區段。To use this algorithm, add the <NetFx45_CultureAwareComparerGetHashCode_LongStrings> element to the <runtime> section of your application's configuration file.

適用於