==
operator to perform value equality checks CS-R1001Operators 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>
.
public class Car
{
public static bool operator==(Car lhs, Car rhs)
{
// ...
}
}
public class Car : IComparable
{
public int CompareTo(object other)
{
// ...
}
}