System.Collections.Generic.IEqualityComparer<T> Interface

public interface IEqualityComparer<T>

Assembly

mscorlib

Library

BCL

Summary

Provides a mechanism to customize equality in sort ordering of a generic collection.

See Also

System.Collections.Generic Namespace

Members

IEqualityComparer<T> Methods

IEqualityComparer<T>.Equals Method
IEqualityComparer<T>.GetHashCode Method


IEqualityComparer<T>.Equals Method

bool Equals(T x, T y)

Summary

Determines whether the specified objects are equal.

Parameters

x
First T to compare.
y
Second T to compare.

Return Value

true if the specified objects are equal; otherwise, false .

Description

An implementation of Equals(T,T) shall satisfy the following: The equality function shall be be reflexive, so x.Equals(x) is true; symmetric, so x.Equals(y) and y.Equals(x); and transitive, so x.Equals(y) and y.Equals(z) implies x.Equals(z); for any values x, y and z for which these expressions are defined.

See Also

System.Collections.Generic.IEqualityComparer<T> Interface, System.Collections.Generic Namespace

IEqualityComparer<T>.GetHashCode Method

int GetHashCode(T obj)

Summary

Returns a hash code for the specified object.

Parameters

obj
The object for which the hash code is to be returned.

Return Value

A hash code for the specified object.

Exceptions

Exception TypeCondition
ArgumentNullExceptionThe type of obj is a reference type and obj is null .

Description

To produce a hash function for the given object. [Note: A hash function is used to quickly generate a number (a hash code) corresponding to the value of an object. Hash functions are used with hashtables . A good hash function algorithm rarely generates hash codes that collide. For more information about hash functions, see The Art of Computer Programming , Vol. 3, by Donald E. Knuth.]

[Behaviors: All implementations are required to ensure that if x.Equals(y) == true, then x.GetHashCode() equals y.GetHashCode(), for any x and y values for which these expressions are defined.

]

See Also

System.Collections.Generic.IEqualityComparer<T> Interface, System.Collections.Generic Namespace