Skip to content

Null Conditional Operator

The null conditional operator ?. accesses a member only if the object is not null.

string text = null;
int? length = text?.Length;
Console.WriteLine(length ?? 0);
Terminal window
dotnet run
Terminal window
0