System.StringComparer.GetHashCode Method

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

Syntax

public abstract int GetHashCode (string obj)

Parameters

obj
A string.

Returns

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

Remarks

The StringComparer.GetHashCode(string) method is more efficient than the StringComparer.GetHashCode(object) method because the obj parameter does not have to be unboxed to perform the operation.

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

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0