Using ? operator for checking the condition is matches or not, it is same as if condition where we can use else if condition also. Using ?? will check the value is null such that we can assign some value. Using : specifies the else condition. Below are the examples.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectName
{
    class Program
    {
        static void Main(string[] args)
        {
            Program pgmObj = new Program();
            Console.WriteLine(pgmObj.GetDepartmentCodes("Administration"));
            Console.WriteLine(pgmObj.isFinance("Finance"));
            Console.WriteLine(pgmObj.assigndefaultValue(null));
            Console.ReadKey();
        }

        public string GetDepartmentCodes(string departmentName) //if else if condition
        {
            return departmentName.Equals("Finance") ? "FIN"
                   departmentName.Equals("Administration") ? "Admin" : "Others";
        }

        public string isFinance(string departmentName) //if else condition
        {
            return departmentName.Equals("Finance") ? "FIN" : "Others";
        }

        public string assigndefaultValue(string departmentName) // check null
        {
            return departmentName ?? "TBD";
        }
    }
}