CSharp - null coalescing Operator

Introduction

?? operator is the null coalescing operator.

If the operand is non-null, ?? gets its value; otherwise, it returns a default value.

If the left hand expression is non-null, the right hand expression is never evaluated.

For example:

string s1 = null;
string s2 = s1 ?? "nothing";   // nothing is assigned to s2

Demo

using System;
class MainClass// www  .  j a  v a2  s.c o m
{
   public static void Main(string[] args)
   {

        string s1 = null;
        string s2 = s1 ?? "book2s.com is default value";

        Console.WriteLine(s2);

   }
}

Result