StringComparer.GetHashCode StringComparer.GetHashCode StringComparer.GetHashCode StringComparer.GetHashCode Method

定义

当在派生类中重写时,将获取当前 StringComparer 对象的哈希代码。When overridden in a derived class, gets the hash code for the current StringComparer object.

重载

GetHashCode(Object) GetHashCode(Object) GetHashCode(Object) GetHashCode(Object)

当在派生类中重写时,将获取指定对象的哈希代码。When overridden in a derived class, gets the hash code for the specified object.

GetHashCode(String) GetHashCode(String) GetHashCode(String) GetHashCode(String)

当在派生类中重写时,将获取指定字符串的哈希代码。When overridden in a derived class, gets the hash code for the specified string.

GetHashCode(Object) GetHashCode(Object) GetHashCode(Object) 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 Object Object 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.

注解

GetHashCode(String)方法是比效率更高GetHashCode方法因为obj参数无需取消装箱来执行该操作。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.

GetHashCode(Object)方法分配的大小成正比的内存量obj若要计算的哈希代码objThe 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) GetHashCode(String) GetHashCode(String) 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 String String 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.

注解

GetHashCode(String)方法是比效率更高GetHashCode(Object)方法因为obj参数无需取消装箱来执行该操作。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.

GetHashCode(String)方法分配的大小成正比的内存量obj若要计算的哈希代码objThe 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.

适用于