c# - Defining operators and testing for null -


i have class in c# define operator ==. method have throws object null exception when testing following

myclass = new myclass(); if(a==null).... 

this frustrating because in definition of operator can't ask if either parameter null because go infinite recursion.

how test see if either parameter null when defining == operator.

use object.referenceequals:

if (object.referenceequals(obja, null)) { ... } 

another option cast obja object:

if ((object)obja == null) { ... } 

you may want consult these guidelines.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -