Can someone explain me what does this overload mean?
public static bool operator ==(Shop lhs, Shop rhs)
{
if (Object.ReferenceEquals(lhs, null))
{
if (Object.ReferenceEquals(rhs, null))
{
return true;
}
return false;
}
return lhs.Equals(rhs);
}
I have never seen Object.ReferenceEquals in overload
This overload was intended to compare two instances of
Shop. It usesObject.ReferenceEqualsto determine if one of the instances isnull.It cannot use
lhs == nullorrhs == null, because this would again invoke theoperator ==and create an infinite recursion leading to aStackOverflowException.If both instances are
nullit returns true (since they are equal).If only one instance is
nullit returns false (since they are not equal).If both instances are not
nullit returns the result of theEqualsimplementation ofShop.