How the right associative of null coalescing operator behaves?

后端 未结 4 1482
Happy的楠姐
Happy的楠姐 2020-12-03 01:20

null coalescing operator is right associative, which means an expression of the form

first ?? second ??third

is eva

4条回答
  •  北海茫月
    2020-12-03 01:48

    Jon's answer is correct.

    Just to be clear: the ?? operator in C# is right associative. I have just gone through the binary operator parser and verified that the parser treats ?? as right-associative.

    As Jon points out, the spec says both that the ?? operator is right-associative, and that all binary operators except assignment are left-associative. Since the spec contradicts itself, clearly only one of these can be right. I will have the spec amended to say something like:

    Except for the simple assignment, compound assignment and null coalescing operators, all binary operators are left-associative

    UPDATE: As noted in the comments, the lambda operator => is also right-associative.

提交回复
热议问题