dotnet / dotnet-api-docs

.NET API reference documentation (.NET 5+, .NET Core, .NET Framework)
https://docs.microsoft.com/dotnet/api/
Other
729 stars 1.56k forks source link

Documentation for EqualityComparer<T> contains wrong remark #5279

Open skrysmanski opened 3 years ago

skrysmanski commented 3 years ago

The current version of the documentation of EqualityComparer<T> contains this in its "Remarks" section:

We recommend that you derive from the EqualityComparer class instead of implementing the IEqualityComparer interface, because the EqualityComparer class tests for equality using the IEquatable.Equals method instead of the Object.Equals method.

I think this statement is completely wrong. The current (.NET 5) implementation of EqualityComparer<T> is like this (only the relevant parts):

public abstract partial class EqualityComparer<T> : IEqualityComparer, IEqualityComparer<T>
{
    public abstract bool Equals(T? x, T? y);
    public abstract int GetHashCode([DisallowNull] T obj);
}

These two abstract methods are the two methods required by IEqualityComparer<T>. There's no "pre-processing" of x and y.

So I don't see what this remark in the documentation would be referring to.

dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

antonfirsov commented 3 years ago

Tagging @eiriktsarpalis @layomia as area owners.