开发者

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

开发者 https://www.devze.com 2022-12-24 16:02 出处:网络
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

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

精彩评论

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

关注公众号