C# 2.0 has the little-known ?? (double question mark) operator which returns the second operand if the first operand is null. It's the equivalent of the NVL or COALESCE function in SQL.
Example:
using System;
class Program
{
static void Main(string[] args)
{
int? cole = null;
string str1 = null;
Console.WriteLine(cole ?? 4);
Console.WriteLine(str1 ?? "Nitin");
Console.ReadLine();
}
}
Friday, December 26, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment