What do two question marks together mean in C#?

前端 未结 18 1342
借酒劲吻你
借酒劲吻你 2020-11-22 03:41

Ran across this line of code:

FormsAuth = formsAuth ?? new FormsAuthenticationWrapper();

What do the two question marks mean, is it some ki

18条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 04:10

    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.

    int? variable1 = null;
    int variable2  = variable1 ?? 100;
    

    Set variable2 to the value of variable1, if variable1 is NOT null; otherwise, if variable1 == null, set variable2 to 100.

提交回复
热议问题