CompareInfo.GetHashCode 方法

定义

返回此 CompareInfo 实例或特定字符串的哈希代码。Returns a hash code either for this CompareInfo instance or for a particular string.

重载

GetHashCode()

用作当前 CompareInfo 的哈希函数,适合在哈希算法和数据结构(如哈希表)中使用。Serves as a hash function for the current CompareInfo for hashing algorithms and data structures, such as a hash table.

GetHashCode(ReadOnlySpan<Char>, CompareOptions)

根据指定的比较选项获取字符范围的哈希代码。Gets the hash code for a character span based on specified comparison options.

GetHashCode(String, CompareOptions)

根据指定的比较选项获取字符串的哈希代码。Gets the hash code for a string based on specified comparison options.

GetHashCode()

用作当前 CompareInfo 的哈希函数,适合在哈希算法和数据结构(如哈希表)中使用。Serves as a hash function for the current CompareInfo for hashing algorithms and data structures, such as a hash table.

public:
 override int GetHashCode();
public override int GetHashCode ();
override this.GetHashCode : unit -> int
Public Overrides Function GetHashCode () As Integer

返回

当前 CompareInfo 的哈希代码。A hash code for the current CompareInfo.

注解

此方法重写 Object.GetHashCodeThis method overrides Object.GetHashCode.

此方法为根据 Equals 方法视为相等的两个对象生成相同的哈希代码。This method generates the same hash code for two objects that are equal according to the Equals method.

另请参阅

GetHashCode(ReadOnlySpan<Char>, CompareOptions)

根据指定的比较选项获取字符范围的哈希代码。Gets the hash code for a character span based on specified comparison options.

public:
 int GetHashCode(ReadOnlySpan<char> source, System::Globalization::CompareOptions options);
public int GetHashCode (ReadOnlySpan<char> source, System.Globalization.CompareOptions options);
override this.GetHashCode : ReadOnlySpan<char> * System.Globalization.CompareOptions -> int
Public Function GetHashCode (source As ReadOnlySpan(Of Char), options As CompareOptions) As Integer

参数

source
ReadOnlySpan<Char>

要返回其哈希代码的字符范围。The character span whose hash code is to be returned.

options
CompareOptions

确定如何比较字符串的值。A value that determines how strings are compared.

返回

32 位有符号整数哈希代码。A 32-bit signed integer hash code.

注解

此重载的行为取决于其实现,该实现可能会从一个版本的公共语言运行时更改为另一个版本,或从一个 .NET 实现更改为另一个版本。The behavior of this overload is dependent on its implementation, which might change from one version of the common language runtime to another, or from one .NET implementation to another.

重要

如果两个字符跨越相等,则此重载返回相同的值。If two character spans are equal, this overload returns identical values. 但是,每个唯一字符跨度值没有唯一的哈希代码值。However, there is not a unique hash code value for each unique character span value. 不同的字符跨度可以返回相同的哈希代码。Different character spans can return the same hash code.

哈希代码本身不一定是稳定的。The hash code itself is not guaranteed to be stable. 对于单个版本的 .net,相同字符跨度的哈希代码在不同版本的 .NET 实现和各种平台(如32位和64位)之间可能会有所不同。Hash codes for identical character spans can differ across versions of the .NET implementations and across platforms (such as 32-bit and 64-bit) for a single version of .NET.

因此,哈希代码决不能在创建它们的应用程序域的外部使用,它们永远不应用作集合中的键字段,它们永远不会保留。As a result, hash codes should never be used outside of the application domain in which they were created, they should never be used as key fields in a collection, and they should never be persisted.

GetHashCode(String, CompareOptions)

根据指定的比较选项获取字符串的哈希代码。Gets the hash code for a string based on specified comparison options.

public:
 virtual int GetHashCode(System::String ^ source, System::Globalization::CompareOptions options);
public virtual int GetHashCode (string source, System.Globalization.CompareOptions options);
override this.GetHashCode : string * System.Globalization.CompareOptions -> int
Public Overridable Function GetHashCode (source As String, options As CompareOptions) As Integer

参数

source
String

要返回其哈希代码的字符串。The string whose hash code is to be returned.

options
CompareOptions

确定如何比较字符串的值。A value that determines how strings are compared.

返回

32 位有符号整数哈希代码。A 32-bit signed integer hash code.

异常

sourcenullsource is null.

注解

GetHashCode 的行为取决于其实现,该实现可能会从公共语言运行时的一个版本更改为另一个版本,或从一个 .NET Framework 平台更改为另一个版本。The behavior of GetHashCode is dependent on its implementation, which might change from one version of the common language runtime to another, or from one .NET Framework platform to another.

重要

如果两个字符串对象相等,则 GetHashCode 方法返回相同的值。If two string objects are equal, the GetHashCode method returns identical values. 但是,每个唯一字符串值没有唯一的哈希代码值。However, there is not a unique hash code value for each unique string value. 不同的字符串可以返回相同的哈希代码。Different strings can return the same hash code.

哈希代码本身不一定是稳定的。The hash code itself is not guaranteed to be stable. 对于同一版本的 .NET Framework,相同字符串的哈希代码可能不同于不同版本的 .NET Framework 和跨平台(例如32位和64位)。Hash codes for identical strings can differ across versions of the .NET Framework and across platforms (such as 32-bit and 64-bit) for a single version of the .NET Framework. 在某些情况下,它们甚至不同于应用程序域。In some cases, they can even differ by application domain.

因此,哈希代码决不能在创建它们的应用程序域的外部使用,它们永远不应用作集合中的键字段,它们永远不会保留。As a result, hash codes should never be used outside of the application domain in which they were created, they should never be used as key fields in a collection, and they should never be persisted.

另请参阅

适用于