Little-known C# 2.0 operator – ??
August 21, 2007 at 2:39 pm 2 comments
Excerpt from the msdn:
The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand.
Example:
string s = null; int? i = null; Console.WriteLine(s ?? "(null)"); Console.WriteLine(i ?? -1);
Will produce:
(null) -1
1.
leppie | August 21, 2007 at 2:41 pm
Very handy for default values
2.
gramotei | August 21, 2007 at 3:06 pm
exactly:)