What is the operator precedence of C# null-coalescing (??) operator?

前端 未结 4 1067
难免孤独
难免孤独 2020-12-05 18:54

I\'ve just tried the following, the idea being to concatenate the two strings, substituting an empty string for nulls.

string a=\"Hello\";
string b=\" World\         


        
4条回答
  •  自闭症患者
    2020-12-05 19:24

    The operator precedence is documented on MSDN.

    However the precedence on MSDN contradicts the precedence in both the downloadable C# spec also from Microsoft, and the spec on ECMA. Which is a little odd.

    Irrespective, as Jon Skeet said in his response, best not to rely on precedence of operators, but to be explicit through use of brackets.

提交回复
热议问题