Is this an if else expression

Possible duplicate:
What do the two question marks in C # mean?

I just came across the code below and am not quite sure what that means and cannot google, because google skips ??

int? x = 32;
int  y = x ?? 5;

Is the second line some kind of if else expression, which means ??

+5
source share
4 answers

He called the null-coalescing statement .

If the value to the left of ??is equal null, use the value to the right of ??, otherwise use the value of the left hand.

Deployed:

y = x == null ? 5 : x

or

if(x == null)
     y = 5
else
     y = x
+12
source
if(x == null)
     y = 5
else
     y = x
+2
source

?? . , :

int? x = null;
int? y = null;
int? z = null;

y = 12;
int? a = x ?? y ?? z;

a 12, y - .

+1

Yes. This is an if else statement. Check out this URL http://www.webofideas.co.uk/Blog/c-sharp-double-question-mark-syntax.aspx

0
source

All Articles