开发者

Why is var m = 6 + + + + + + + + 6; valid in c#?

Title is most of the question, what allows this to be valid code? Is there any benefit or trick that would al开发者_开发知识库low me to utilize this?


The unary plus operator has higher precedence than the addition operator, just split your expression into multiple grouped expressions and it will seem pretty obvious:

var m = 6 + ( +( +( +( +( +( +( +( 6 ))))))));
      //6 + 6


The extra pluses are being treated as positive indicators. As in +1.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜