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. 对于大字符串,尝试检索哈希代码可能会引发ArgumentExceptionIn 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. 对于大字符串,尝试检索哈希代码可能会引发ArgumentExceptionIn 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.

适用于