StringComparer.GetHashCode Method (Object)


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

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

public int GetHashCode(
	object obj


Type: System.Object

An object.

Return Value

Type: System.Int32

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

Exception Condition

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

.NET Framework
Available since 2.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top