In C#, how can we check reference equality for a type that implements equality operator?
class C
{
public int Val{get;set;}
public static bool operator =
What does object "object equality"?
If by "how can we check object equality for a type that implements equality operator?", you actually mean "how can we check object equality for a type that implements IEquatable
", the short answer is...however you want (with some caveats).
The documentation for IEquatableIEquatable
and IComparable
, it would make sense if your Equals()
method returns true
for all the cases where your CompareTo()
method returns 0, and for your Equals()
method to return false
for all the cases where your CompareTo()
method returns a non-zero value.
Further, you might want to ensure that you properly override ==
and !=
to provide the same behaviour as calling Equals().