Home >Backend Development >C++ >What Does the Double Question Mark (??) Operator Do in C#?
Double question sign (??) The meaning of the operator of the operator
In the following code line:
Two question marks (??) represents an air merger operator. Unlike the ternary operator, the air merger operator executes the conditional assignment, not the conditions for execution.
<code class="language-csharp">FormsAuth = formsAuth ?? new FormsAuthenticationWrapper();</code>
Specifically, the expression
equivalent to:
formsAuth ?? new FormsAuthenticationWrapper()
<code class="language-csharp">FormsAuth = formsAuth != null ? formsAuth : new FormsAuthenticationWrapper();</code>
If is not null, it assigns it to
formsAuth
If FormsAuth
is assigned to formsAuth
FormsAuthenticationWrapper
In short, it means "if FormsAuth
is not null, use
formsAuth
Unlike the ternary computing symbols, the air merger operator only evaluates its expression once. Therefore, if is called by side effects, its side effects will only trigger once. formsAuth
FormsAuthenticationWrapper
In order to further explain, the following expressions will assign the first non -empty ANSWER to ANSWER. If all ANSWER is NULL, then ANSWER will remain as NULL:
The above is the detailed content of What Does the Double Question Mark (??) Operator Do in C#?. For more information, please follow other related articles on the PHP Chinese website!