Wednesday, July 26, 2006

C# 2.0 new features: ?? operator (null coalscing operator)

?? (null coalescing operator)
A new operator included in C# 2.0. It will check something for null, return the same something if it’s not null, the given alternative value otherwise.

Example:
int? x = null;
int y = x ?? -1;

This will assign the value of variable 'x' to variable 'y' if it is not null. Else will assign '-1' to variable 'y'.

Everything fine. What is that notation '?' used here? Is this question raised to you here? Wait till my next article on new features of c# 2.0.

C U later....

:)

No comments:

Post a Comment