public interface IEqualityComparer<T>
mscorlib
BCL
Provides a mechanism to customize equality in sort ordering of a generic collection.
System.Collections.Generic Namespace
IEqualityComparer<T> Methods
IEqualityComparer<T>.Equals Method
IEqualityComparer<T>.GetHashCode Method
bool Equals(T x, T y)
Determines whether the specified objects are equal.
- x
- First
T
to compare.- y
- Second
T
to compare.
true
if the specified objects are equal; otherwise,false
.
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.
System.Collections.Generic.IEqualityComparer<T> Interface, System.Collections.Generic Namespace
int GetHashCode(T obj)
Returns a hash code for the specified object.
- obj
- The object for which the hash code is to be returned.
A hash code for the specified object.
Exception Type Condition ArgumentNullException The type of obj is a reference type and obj is null
.
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 withhashtables
. 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.
]
System.Collections.Generic.IEqualityComparer<T> Interface, System.Collections.Generic Namespace