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

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -