Using Null Coalescing Operator in C#

Sometimes , you may want to simply the Null checks in your .NET Program without much usage of the if statements .

The Null Coalescing Operator can be used in this scenario.

Using Null Coalescing Operator in C#

using System;
namespace AbundantCode
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            Employee emp = new Employee { Name = "Mark", ID = 1 };
            var returnvalue = emp ?? new Employee();

            Console.WriteLine(returnvalue.Name);
            Console.ReadLine();
        }
    }
}