CompareInfo.GetHashCode Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a hash code either for this CompareInfo instance or for a particular string.
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. |
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
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
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
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
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
- Source:
- CompareInfo.cs
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
.NET 9 and other versions
Product | Versions |
---|---|
.NET | Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: