CSharp - Nullable Types and Null Operators

Introduction

Nullable types work well with the ?? operator. For example:

Demo

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

        int? x = null;
        int y = x ?? 5;        // y is 5
        
        int? a = null, b = 1, c = 2;
        Console.WriteLine (a ?? b ?? c);  // 1 (first non-null value)

   }
}

Result