Skip to content
Discussion options

You must be logged in to vote

sealed class ReallyComparable : IEquatable<ReallyComparable?> // treats null as equal to anything

This is notably an illegal and invalid implementation

Equals and GetHashCode (and by extension IEquatable<T>.Equals) have implementation contracts you are required to fulfill. See also https://learn.microsoft.com/en-us/dotnet/api/system.iequatable-1?view=net-10.0#notes-to-implementers and https://learn.microsoft.com/en-us/dotnet/api/system.object.equals?view=net-10.0#notes-for-inheritors

In particular (especially note the last bullet):

The following statements must be true for all implementations of the Equals(Object) method. In the list, x, y, and z represent object references that are no…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@quixoticaxis
Comment options

Comment options

You must be logged in to vote
1 reply
@quixoticaxis
Comment options

Answer selected by quixoticaxis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants