StringComparer.GetHashCode Method

Definition

When overridden in a derived class, gets the hash code for the current StringComparer object.

Overloads

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.

GetHashCode(String)

Source:
StringComparer.cs
Source:
StringComparer.cs
Source:
StringComparer.cs

When overridden in a derived class, gets the hash code for the specified string.

C#
public abstract int GetHashCode(string obj);

Parameters

obj
String

A string.

Returns

A 32-bit signed hash code calculated from the value of the obj parameter.

Implements

Exceptions

Not enough memory is available to allocate the buffer that is required to compute the hash code.

obj is null.

Remarks

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.

The GetHashCode(String) method allocates an amount of memory that is proportional to the size of obj to calculate the hash code of obj. In 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. To use this algorithm, add the <NetFx45_CultureAwareComparerGetHashCode_LongStrings> element to the <runtime> section of your application's configuration file.

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.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, 10
.NET Framework 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.5, 1.6, 2.0, 2.1
UWP 10.0

GetHashCode(Object)

Source:
StringComparer.cs
Source:
StringComparer.cs
Source:
StringComparer.cs

When overridden in a derived class, gets the hash code for the specified object.

C#
public int GetHashCode(object obj);

Parameters

obj
Object

An object.

Returns

A 32-bit signed hash code calculated from the value of the obj parameter.

Implements

Exceptions

Not enough memory is available to allocate the buffer that is required to compute the hash code.

obj is null.

Remarks

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.

The GetHashCode(Object) method allocates an amount of memory that is proportional to the size of obj to calculate the hash code of obj. In 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. To use this algorithm, add the <NetFx45_CultureAwareComparerGetHashCode_LongStrings> element to the <runtime> section of your application's configuration file.

Applies to

.NET 10 i druge verzije
Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 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 2.0, 2.1