Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • 1
    Exactly. Both (object)foo1 == null or foo1 == (object)null will go to the built-in overload ==(object, object) and not to the user-defined overload ==(Foo, Foo). It is just like overload resolution on methods. Commented Jun 4, 2014 at 11:47
  • 2
    To future visitors - the accepted answer is a function, that executes the == of object. This is basically the same as the accepted answer, with one downside: It needs a cast. The accpeted answer is thus superior. Commented Jul 8, 2016 at 12:43
  • 1
    @Mafii The cast is purely a compile time operation. Since the compiler knows that the cast cannot fail, it need not check anything at runtime. The differences between the methods are completely aesthetic. Commented Jun 5, 2017 at 20:43