System.Collections.IHashCodeProvider Interface

public interface IHashCodeProvider

Assembly

mscorlib

Library

BCL

Summary

Implemented by classes that support custom hash functions for instances of the class.

Description

[Note: IHashCodeProvider contains the System.Collections.IHashCodeProvider.GetHashCode(System.Object) method. The consumer of an object should call this method to obtain a hash code for the object using a custom hash function.]

See Also

System.Collections Namespace

Members

IHashCodeProvider Methods

IHashCodeProvider.GetHashCode Method


IHashCodeProvider.GetHashCode Method

int GetHashCode(object obj);

Summary

Generates a hash code for the specified Object.

Parameters

obj
The Object for which a hash code is to be generated.

Return Value

A Int32 containing the hash code for the specified Object.

Exceptions

Exception TypeCondition
ArgumentNullExceptionobj is null .

Description

[Behaviors: If obj is null , it is required that a call to System.Collections.IHashCodeProvider.GetHashCode(System.Object) throw ArgumentNullException.]

[Overrides: Implement this method to generate a better hash table distribution than the default method provided by the type of the Object for which the hash code is being generated.]

[Usage: The value returned by this method should not be persisted past the lifetime of the application that created the value. The first reason is that the hash function of a class may be altered to generate a better distribution, rendering any values from the old hash function useless. The second reason is that the default implementation of this class does not guarantee that the same value will be returned by different instances.]

See Also

System.Collections.IHashCodeProvider Interface, System.Collections Namespace