dotnet / dotnet/dotnet-api-docs

Documentation for EqualityComparer<T> contains wrong remark

Open
#5,279 2 comments 0 reactions 0 assignees View on GitHub
area-System.Collections Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

The current version of the [documentation of `EqualityComparer`](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.equalitycomparer-1?view=net-5.0) 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`](https://github.com/dotnet/runtime/blob/6cf1b8ec012d52880d46fa4773f60ed52ddc9f3d/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs) is like this (only the relevant parts):

```c#
public abstract partial class EqualityComparer : IEqualityComparer, IEqualityComparer
{
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`. There's no "pre-processing" of `x` and `y`.

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.