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
.
精彩评论