There is no =+ operator in C#; n =+ 1 will be understood by the compiler as n = +1. The unary + operator exists as a complement to the unary - operator (negation), though as you've noticed it doesn't generally do much. :-)
-Tom Meschter Software Dev, Visual C# IDE
Ah, duh. I shall slap myself repeatedly. Thanks to both!
There is no =+ operator in C#; n =+ 1 will be understood by the compiler as n = +1. The unary + operator exists as a complement to the unary - operator (negation), though as you've noticed it doesn't generally do much. :-)
What's the difference between += and =+?
Tsuru
n += 1 (n = n + 1)
n =+ 1 ( )
Al Dynarski
Ah, duh. I shall slap myself repeatedly. Thanks to both!
JoeCoder
-Tom Meschter
Software Dev, Visual C# IDE
RajKS
n =+ 1;
The compiler will understand it as:
n = (+1);
The compiler sees an assignment expression not an addition operation like you might be thinking.
Curious though is to know how this is considered a valid expression:
n = +n;
Anyone
DTSlurve
n = 42;
n = -n; // n is now -42
For unary plus:
n = 42;
n = +n; // n is still 42
The unary plus operator is a NOP, but included for mathematical completeness, as far as I understand.