IComparer interface is to Comparison delegate as IEqualityComparer is to what?

.net, c#

Solution

There is no equivalent because there can't be one. `IComparer<T>` defines only a single member, so you can "distill" it into a delegate.

In contrast, `IEqualityComparer<T>` must provide both `Equals` and `GetHashCode` implementations in order to be universally useful. You can't fit both of these into a delegate, hence no equivalent to `Comparison<T>`.

That said, the signature of a delegate that directly compares two instances of a type `T` for equality would be the one given for `EqualityComparer<T>.Equals` -- i.e. `Func<T, T, bool>`.

Problem

I like the Comparison delegate, it's easier to make one than an IComparer. Is there an analogous delegate for IEqualityComparer? IComparer interface is to Comparison delegate as IEqualityComparer is to what?

Original source