Skip to content

Null Coalescing Operator

The null coalescing operator ?? returns the left-hand operand if not null, else the right.

string name = null;
string display = name ?? "Guest";
Console.WriteLine(display);
Terminal window
dotnet run
Terminal window
Guest