The ?? operator is also known as the null-coalescing operator. It
returns the left side operand if the operand is not null else it returns
the right side operand.
int? x = null;
int y = x ?? 99;
Console.WriteLine("The Value of 'Y' is:" + y);
string message = "Operator Test";
string resultMessage = message ?? "Original message is null";
Console.WriteLine("The value of result message is:" + resultMessage);
In the preceding example, we have an integer variable "x" that is a
nullable type and has a null value so in the result variable "Y" the
return value is 99. The same is in the second example. We could check
whether the message was null and return an alternate value and result
message return "Operator test because message variable has value.
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Can you answer this question?
Write Answer1 Answers