IObject: GetHashCode

GetHashCode

Serves as a hash function for a particular type.



 Public Function GetHashCode ( ) As Long

Return Values

Long -  A hash code for the current IObject.

Remarks

A hash code is a numeric value that is used to identify an object during equality testing. It can also serve as an index for an object in a collection.

The GetHashCode method is suitable for use in hashing algorithms and data structures such as a hash table.

The default implementation of the GetHashCode method does not guarantee unique return values for different values. Furthermore, VBCorLib does not guarantee the default implementation of the GetHashCode method, and the value it returns will be the same between different versions of VBCorLib. Consequently, the default implementation of this method must not be used as a unique object identifier for hashing purposes.

Notes to Implementers
A hash function is used to quickly generate a number (hash code) that corresponds to the value of an object. Hash functions are usually specific to each Type and, for uniqueness, must use at least one of the instance fields as input. A hash function must have the following properties:

Implementations of the GetHashCode method must not result in circular references. For example, if ClassA.GetHashCode calls ClassB.GetHashCode, ClassB.GetHashCode must not call ClassA.GetHashCode either directly or indirectly.

Implementations of the GetHashCode method must not throw exceptions.

Examples

The following code demonstrates an implementation of the GetHashCode method. This does not show the complete implementation of the IObject interface.

Implements IObject

Public X As Long

Public Y As Long


Public Function GetHashCode() As Long
    GetHashCode = X Xor Y
End Function


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'   IObject
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function IObject_GetHashCode() As Long
    IObject_GetHashCode = GetHashCode
End Function

See Also

Project CorLib Overview

Class IObject Overview