Click to see the query in the CodeQL repository
When an ordering is introduced on instances of a class by making the class implement the IComparable interface, it is sensible to ensure that for all instances c1 and c2, c1.CompareTo(c2) == 0 ⇔ c1.Equals(c2). Classes that implement IComparable.CompareTo but inherit Equals, rather than overriding it to match the CompareTo implementation, generally violate this assumption, which can lead to confusion when the class is used.
If the type implements IComparable, it should override Equals.
- Microsoft: Guidelines for Overloading Equals() and Operator ==
A class that implements CompareTo should generally also override Equals in order to provide a consistent implementation.
The following example outputs:
This is obviously not desirable as shows an inconsistency between the behavior of CompareTo and the behavior of Equals.
MSDN: IComparable.CompareTo Method.