22 September 2009

Null Coalescing

I had seen this before, but now it hit me:

?? is an operator in .NET 2.0 and up.


So all those lines of code that look like this:

int myInt = (myNullableInt.HasValue) ? myNullableInt.Value : 0;

can now look like this:

int myInt = myNullableInt ?? 0;


No comments:

Post a Comment