I have a class that I want to overload the == operator for in c#. I already have a .Equals override that works properly. When I tried to use my == operator, it gave me a null reference exception on my object (Person). If I try to check if it is null, it will in turn call the same operator to check it against null and create an infinite loop. This seems like a huge flaw and I can't figure out the right way 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);
}