System.Collections.IHashCodeProvider Interface

Assembly: Mscorlib.dll
Namespace: System.Collections
Summary
Supplies a hash code for an object, using a custom hash function.
C# Syntax:
public interface IHashCodeProvider
Remarks
The IHashCodeProvider interface is used in conjunction with Hashtable. The objects used as keys by a Hashtable must implement or inherit the Object.GetHashCode and Object.Equals methods. Object.GetHashCode or the key's implementation of Object.GetHashCode is used as the hash code provider. Object.Equals or the key's implementation of Object.Equals is used as the comparer.

However, some overloads of the Hashtable constructor take a parameter that is an IHashCodeProvider implementation, or a parameter that is an IComparer implementation, or both. If an IHashCodeProvider implementation is passed to the constructor, the IHashCodeProvider.GetHashCode of that implementation is used as the hash code provider. If an IComparer implementation is passed to the constructor, the IComparer.Compare of that implementation is used as the comparer.

See also:
System.Collections Namespace | Hashtable | IHashCodeProvider | IComparer | CaseInsensitiveHashCodeProvider

System.Collections.IHashCodeProvider Member List:

Public Methods
GetHashCode Returns a hash code for the specified object.

System.Collections.IHashCodeProvider Member Details

Method: GetHashCode(
   object obj
)
Summary
Returns a hash code for the specified object.
C# Syntax:
int GetHashCode(
   object obj
);
Parameters:

obj

The Object for which a hash code is to be returned.

Return Value:
A hash code for the specified object.
Remarks
The return value from this method must not be persisted for two reasons. First, the hash function of a class might be altered to generate a better distribution, rendering any values from the old hash function useless. Second, the default implementation of this class does not guarantee that the same value will be returned by different instances.
See also:
Object.GetHashCode

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.