Export (0) Print
Expand All

IEquatable(T) Interface

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)

type IEquatable<'T> =  interface end

Type Parameters


The type of objects to compare.

The IEquatable(T) type exposes the following members.

Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsEqualsIndicates whether the current object is equal to another object of the same type.

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.


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

The IEquatable(T) interface is used by generic collection objects such as Dictionary(TKey, TValue), List(T), and LinkedList(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(T) interface with the type that is implementing this interface.

If you implement IEquatable(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(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. In addition, you should overload the op_Equality and op_Inequality operators. This ensures that all tests for equality return consistent results.


For information on overriding Equals(Object), see the Object.Equals(Object) article.

For a value type, you should always implement IEquatable(T) and override Object.Equals(Object) for better performance. Object.Equals boxes value types and relies on reflection to compare two values for equality. Both your implementation of Equals and your override of Object.Equals should return consistent results.

If you implement IEquatable(T), you should also implement IComparable(T) if instances of your type can be ordered or sorted. If your type implements IComparable(T), you should also always implement IEquatable(T).

See the example for the IEquatable(T).Equals method.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft