jeudi 30 août 2018

Is "if(!myobject)" the same as "if(myobject == null)"?

Today I've come across an interesting bit of C# code:

if(!myobject) { /*Do Stuff*/ }

It does seem to behave the same as:

if(myobject == null) { /*Do Stuff*/ }

... but is it really the same thing? I haven't found any documentation about this anywhere yet.

Is there a reason to not use the shorter version or prefer one over the other?

Aucun commentaire:

Enregistrer un commentaire