Double question mark(??) operator in C#

I was going through the nerddinner AccountController code. I have encountered ?? operator.

I figured, it is just a shortcut of assigning an object value based on other objects null value.

For example,

//instance b is of type Class1 and may be null
Class1 a = b ?? new Class1();

We can re-write the code in expanded mode like this:

Class1 a;
if(b!=null)
a=b;
else
a=new Class1();

Comments