Introduction
"Null coalescing" operator is the
language features of c#, which provide the sort way to check weather a value
is null. ?? operator checks whether the
value provided on the left side and right side. If operand is null then
return the right-hand operand or if operand is not null then return
left-hand operand. For example :
Example
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
null_coalescing_operator_in_c_sharp
{
class
Program
{
static
void Main(string[]
args)
{
//create string,
which value is null
string N1 =
null ??
"Null value";
//create string,
which value is not null
string N2 =
"Arvind" ??
"Not empty";
//show value of
strings
Console.WriteLine("Show
right operand: {0}\nSsow left operand : {1}", N1,
N2);
Console.ReadLine();
}
}
}
Output: