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
to give someone more work or problems than they can deal with: Try not to overload yourself with work. SMART Vocabulary: related words and phrases. Filling and completing.
to load to excess; overburden: Don't overload the raft or it will sink. an excessive load.
Adjective. overloaded (comparative more overloaded, superlative most overloaded) loaded too heavily. of a word, having multiple meanings depending on context. (computing) of a name, used for more than one variable or procedure etc; differentiated by the compiler based on context.
This overload was intended to compare two instances of Shop. It uses Object.ReferenceEquals to determine if one of the instances is null.
It cannot use lhs == null or rhs == null, because this would again invoke the operator == and create an infinite recursion leading to a StackOverflowException.
If both instances are null it returns true (since they are equal).
If only one instance is null it returns false (since they are not equal).
If both instances are not null it returns the result of the Equals implementation of Shop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With