Ran across this line of code:
FormsAuth = formsAuth ?? new FormsAuthenticationWrapper();
What do the two question marks mean, is it some kind of ternary operator? It’s hard to look up in Google.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s the null coalescing operator, and quite like the ternary (immediate-if) operator. See also ?? Operator – MSDN.
expands to:
which further expands to:
In English, it means ‘If whatever is to the left is not null, use that, otherwise use what’s to the right.’
Note that you can use any number of these in sequence. The following statement will assign the first non-null
Answer#toAnswer(if all Answers are null then theAnsweris null):Also it’s worth mentioning while the expansion above is conceptually equivalent, the result of each expression is only evaluated once. This is important if for example an expression is a method call with side effects. (Credit to @Joey for pointing this out.)