Export (0) Print
Expand All

StringComparer.GetHashCode Method (String)

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public abstract int GetHashCode(
	string obj


Type: System.String

A string.

Return Value

Type: System.Int32
A 32-bit signed hash code calculated from the value of the obj parameter.




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


obj is null.

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.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft