C#

C#

Made by DeepSource

Implementing IComparable<T> may be particularly useful CS-R1106

Anti-pattern
Major

The specified class has a method whose signature resembles IComparable<T>::CompareTo(T? other) but does not implement IComparable<T>. If your method indeed performs a comparison between 2 objects of the same type, it may be particularly useful to implement the IComparable<T> interface which is defined exactly for purposes like these.

Bad Practice

class C
{
    public int CompareTo(C? other)
    {
        // ...
    }
}

Recommended

class C : IComparable<C>
{
    public int CompareTo(C? other)
    {
        // ...
    }
}