StringComparer.GetHashCode Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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.
public:
abstract int GetHashCode(System::String ^ obj);
public abstract int GetHashCode (string obj);
override this.GetHashCode : string -> int
Public MustOverride Function GetHashCode (obj As String) As Integer
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
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.
public:
virtual int GetHashCode(System::Object ^ obj);
public:
int GetHashCode(System::Object ^ obj);
public int GetHashCode (object obj);
override this.GetHashCode : obj -> int
Public Function GetHashCode (obj As Object) As Integer
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.