Indicates whether the current object is equal to another object of the same type.
Assembly: mscorlib (in mscorlib.dll)
The implementation of the method is intended to perform a test for equality with another object of type T, the same type as the current object. The method is called in the following circumstances:
When the Equals method is called and the other parameter represents a strongly-typed object of type T. (If other is of type Object, the base Object.Equals(Object) method is called. Of the two methods, offers slightly better performance.)
When the search methods of a number of generic collection objects are called. Some of these types and their methods include the following:
Some of the generic overloads of the BinarySearch method.
In other words, to handle the possibility that objects of a class will be stored in an array or a generic collection object, it is a good idea to implement IEquatable(T) so that the object can be easily identified and manipulated.
When implementing the method, define equality appropriately for the type specified by the generic type argument. For example, if the type argument is Int32, define equality appropriately for the comparison of two 32-bit signed integers.Notes to Implementers
If you implement , you should also override the base class implementations of Object.Equals(Object) and GetHashCode so that their behavior is consistent with that of the 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, which the example illustrates.
The following example shows the partial implementation of a Person class that implements IEquatable(T) and has two properties, LastName and SSN. The method returns True if the SSN property of two Person objects is identical; otherwise, it returns False.
Person objects can then be stored in a List(T) object and can be identified by the Contains method, as the following example shows.
.NET FrameworkSupported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
Portable Class LibrarySupported in: Portable Class Library
.NET for Windows Store appsSupported in: Windows 8
.NET for Windows Phone appsSupported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1
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.