C#

C#

Made by DeepSource

Do not overload the == operator to perform value equality checks CS-R1001

Anti-pattern
Major

Operators such as == and != are expected to perform reference comparisons rather than compare values. If you intend to compare two different objects, consider implementing a relevant method in your class or look into interfaces such as IComparable<T> and IEquatable<T>.

Bad Practice

public class Car
{
    public static bool operator==(Car lhs, Car rhs)
    {
        // ...
    }
}

Recommended

public class Car : IComparable
{
    public int CompareTo(object other)
    {
        // ...
    }
}

Reference