Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
System Namespace
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
IEquatable<(Of <(T>)>) Interface

Updated: July 2008

Defines a generalized method that a value type or class implements to create a type-specific method for determining equality of instances.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Visual Basic (Declaration)
Public Interface IEquatable(Of T)
Visual Basic (Usage)
Dim instance As IEquatable(Of T)
C#
public interface IEquatable<T>
Visual C++
generic<typename T>
public interface class IEquatable
J#
J# supports the use of generic APIs, but not the declaration of new ones.
JScript
JScript does not support generic types or methods.

Type Parameters

T

The type of objects to compare.

This interface is implemented by types whose values can be equated (for example, the numeric and string classes). A value type or class implements the Equals method to create a type-specific method suitable for determining equality of instances.

Note:

The IComparable<(Of <(T>)>) interface defines the CompareTo method, which determines the sort order of instances of the implementing type. The IEquatable<(Of <(T>)>) interface defines the Equals method, which determines the equality of instances of the implementing type.

The IEquatable<(Of <(T>)>) interface is used by generic collection objects such as Dictionary<(Of <(TKey, TValue>)>), List<(Of <(T>)>), and LinkedList<(Of <(T>)>) when testing for equality in such methods as Contains, IndexOf, LastIndexOf, and Remove. It should be implemented for any object that might be stored in a generic collection.

Notes to Implementers:

Replace the type parameter of the IEquatable<(Of <(T>)>) interface with the type that is implementing this interface.

If you implement IEquatable<(Of <(T>)>), you should also override the base class implementations of Object..::.Equals(Object) and GetHashCode so that their behavior is consistent with that of the IEquatable<(Of <(T>)>)..::.Equals method. If you do override Object..::.Equals(Object), your overridden implementation is also called in calls to the static Equals(System.Object, System.Object) method on your class. This ensures that all invocations of the Equals method return consistent results.

See the example for the IEquatable<(Of <(T>)>)..::.Equals method.

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 2.0, 1.0

Date

History

Reason

July 2008

Added additional detail on method usage.

Information enhancement.

July 2008

Added notes for implementers.

Information enhancement.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker