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
Post a Comment