What is the use of Null Coalescing Operator (??) in C#?

Technology CommunityCategory: C#What is the use of Null Coalescing Operator (??) in C#?
VietMX Staff asked 4 years ago

The ?? operator is called the null-coalescing operator and is used to define a default value for nullable value types or reference types. It returns the left-hand operand if the operand is not null; otherwise, it returns the right operand.

string name = null;  
string myname = name ?? "Laxmi";  
Console.WriteLine(myname);