CompareInfo.GetHashCode Method

Definition

Returns a hash code either for this CompareInfo instance or for a particular string.

Overloads

GetHashCode(String, CompareOptions)

Gets the hash code for a string based on specified comparison options.

GetHashCode()

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.

public:
 virtual int GetHashCode(System::String ^ source, System::Globalization::CompareOptions options);
public:
 int GetHashCode(System::String ^ source, System::Globalization::CompareOptions options);
public virtual int GetHashCode (string source, System.Globalization.CompareOptions options);
public 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
Public Function GetHashCode (source As String, options As CompareOptions) As Integer

Parameters

source
String

The string whose hash code is to be returned.

options
CompareOptions

A value that determines how strings are compared.

Returns

A 32-bit signed integer hash code.

Exceptions

source is null.

Remarks

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.

Important

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. 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.

See also

Applies to

GetHashCode()

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

Returns

A hash code for the current CompareInfo.

Remarks

This method overrides Object.GetHashCode.

This method generates the same hash code for two objects that are equal according to the Equals method.

See also

Applies to

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

Parameters

source
ReadOnlySpan<Char>

The character span whose hash code is to be returned.

options
CompareOptions

A value that determines how strings are compared.

Returns

A 32-bit signed integer hash code.

Remarks

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.

Important

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. 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.

Applies to