Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
GetHashCode Method (String)
Collapse the table of content
Expand the table of content

StringComparer.GetHashCode Method (String)

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

Namespace:  System
Assemblies:   System.Runtime.Extensions (in System.Runtime.Extensions.dll)
  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

XNA Framework

Supported in: 3.0, 2.0, 1.0

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
© 2015 Microsoft