The c# double question mark operator

Facebook
Twitter
LinkedIn

Never miss a post!

Sign up for our newsletter and get FREE Development Trends delivered directly to your inbox.

You can unsubscribe any time. Terms & Conditions.
Categories

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.

For example

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";
Facebook
Twitter
LinkedIn

Our website uses cookies that help it to function, allow us to analyze how you interact with it, and help us to improve its performance. By using our website you agree by our Terms and Conditions and Privacy Policy.