Click to Rate and Give Feedback
TechNet
TechNet Library
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2010/.NET Framework 4

Other versions are also available for the following:
.NET Framework Class Library
IEqualityComparer Interface

Defines methods to support the comparison of objects for equality.

Namespace:  System.Collections
Assembly:  mscorlib (in mscorlib.dll)
Visual Basic
<ComVisibleAttribute(True)> _
Public Interface IEqualityComparer
C#
[ComVisibleAttribute(true)]
public interface IEqualityComparer
Visual C++
[ComVisibleAttribute(true)]
public interface class IEqualityComparer
F#
[<ComVisibleAttribute(true)>]
type IEqualityComparer =  interface end

The IEqualityComparer type exposes the following members.

  NameDescription
Public methodSupported by the XNA FrameworkEqualsDetermines whether the specified objects are equal.
Public methodSupported by the XNA FrameworkGetHashCodeReturns a hash code for the specified object.
Top

This interface allows the implementation of customized equality comparison for collections. That is, you can create your own definition of equality, and specify that this definition be used with a collection type that accepts the IEqualityComparer interface. In the .NET Framework, constructors of the Hashtable, NameValueCollection, and OrderedDictionary collection types accept this interface.

This interface supports only equality comparisons. Customization of comparisons for sorting and ordering is provided by the IComparer interface.

For the generic version of this interface, see System.Collections.Generic..::.IEqualityComparer<(Of <(T>)>).

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Hash based collections and comparable interface (earlier versions of .NET)      692248CA-C597-49CF-B96F-600D39843454   |   Edit   |   Show History
To work properly in a hashable context, it is a basic rule that if two items are equal (or equivalent) then their hash values must be the same. Therefore, one needs to implement an override of T.GetHashCode() as part of implementing any form of IEqualityComparer<> or IComparer<> interface. This should have been a requirement of the interfaces and the hashable collection types. This would seem to be an issue in the .NET framework design.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker