I have a class that I want to overload the == operator for C #. I already have a .Equals override that works correctly. When I tried to use my == operator, it gave me a reference exception to my object (Person). If I try to check if it is null, it, in turn, will call the same statement to check it for null and create an infinite loop. This seems like a huge flaw, and I can't figure out how to do it.
public static bool operator ==(Person person, object obj) { return person == null ? person.Equals(obj) : false; } public static bool operator !=(Person person, object obj) { return !(person == obj); }
source share