Thursday, July 27, 2017

null-coalescing operator ?? double question-mark

The ?? operator is called the null-coalescing operator. It returns the left-hand operand if the operand is not null; otherwise it returns the right hand operand.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-conditional-operator

(also see:  https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-conditional-operators )

not to be confused with:
The conditional operator (?:) returns one of two values depending on the value of a Boolean expression. Following is the syntax for the conditional operator.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-operator


There's another more generalized name for this kind of expression, but I cannot recall what it is.  I think I have another page about it somewhere. TERNARY!  ternary operator ....  

ternary because it is composed of "3 parts".


var  thingamajig= Request.QueryString["thingamajig"] ?? Request.Form["thingamajig"];


No comments: