Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

Title is most of the question, what allows this to be valid code? Is there any benefit or trick that would allow me to utilize this?

like image 618
Dested Avatar asked Mar 27 '10 07:03

Dested


1 Answers

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
like image 144
Christian C. Salvadó Avatar answered Sep 25 '22 19:09

Christian C. Salvadó