c# - How to handle null if passed from a calling function to a called function whose parameter is nullable integer? -


i have been asked question in interview

public int add(int? a, int? b) {     return a+b; } 

null passed in a's place. how handle this?

i said

if (a == null ) { //do } else { // } 

he didnot anything.

waiting reply.

whtever have said correct interviewer might wanted know how updated are..

 if(!a.hasvalue)     {         = 0;     } 

or shorter :-

a = != null ? : 0; 

and 1 more operator suggested askolein ?? shown below :-

a ?? 0; 

Comments

Popular posts from this blog

javascript - IndexedDB error: Uncaught DataCloneError: Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned -

amazon web services - When using Cognito credentials with AWS in a browser (javascript), keep getting "missing credentials" error -

c# - How to set the datatextfield value instead of the value on a drop down list? -