The C# double question mark operator ?? is called the null-coalescing operator. It is used to return the left hand side operand of the operator if the value is not null and the right hand side operand if the value is null.
string value = null; string text = value ?? "The value is null"
Output value is “The value is null”.
The advantage of this operator is that is simplifies the code and makes the code more readable.
In C# 8 a new ??= null-coalescing operator was introduced. This operator assigns the value of its right hand operand to the left hand operand only if the left-hand operand evaluates to a null value.
string value = null; value ??= "The value is null";