What is the difference between IEqualityComparer<T> and IEquatable<T>?

Tilak picture Tilak · Feb 16, 2012 · Viewed 26k times · Source

I want to understand the scenarios where IEqualityComparer<T> and IEquatable<T> should be used. The MSDN documentation for both looks very similar.

Answer

Justin Niessner picture Justin Niessner · Feb 16, 2012

IEqualityComparer<T> is an interface for an object that performs the comparison on two objects of the type T.

IEquatable<T> is for an object of type T so that it can compare itself to another of the same type.