Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this overload mean?

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

like image 734
Madness Avatar asked Jan 12 '16 06:01

Madness


People also ask

What does overload yourself mean?

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.

Is overload a real word?

to load to excess; overburden: Don't overload the raft or it will sink. an excessive load.

What is the adjective of overload?

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.


1 Answers

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.

like image 151
René Vogt Avatar answered Oct 09 '22 11:10

René Vogt