StringComparer: GetHashCode

GetHashCode

Returns a partially unique numeric representation of the value.



 Public Function GetHashCode(
	  ByRef Obj As Variant ) As Long

Parameters

Obj
[ByRef] Variant. The value to generate a hash code for.

Return Values

Long -  A partially unique number representing the value.

Remarks

Two values could generate the same hash code, but still not be equal. If two values generate the same hash code then additional comparisons should be done to check for equality.

The example is the implementation used by the StringComparer.Ordinal and StringComparer.OrdinalIgnoreCase implementation.

    Private Function StringComparer_GetHashCode(Obj As Variant) As Long
        If VarType(Obj) = vbString Then
            If mStringComparison = OrdinalIgnoreCase Then
                StringComparer_GetHashCode = Object.GetHashCode(UCase$(Obj))
                Exit Function
            End If
        End If

        StringComparer_GetHashCode = Object.GetHashCode(Obj)
    End Function
 

See Also

Project CorLib Overview

Class StringComparer Overview