Sunday, October 30, 2011

C# ?? operator (null coalescing operator)

int? a=null; //int? means a nullabe int. In other words an int variable that can be set to null
int? b;

b = 5;
int? c = a ?? b;//This means pick a if it is not null, else pick b

Console.WriteLine(c);//Displays 5

No comments:

Post a Comment

Comments will appear once they have been approved by the moderator