Possible Duplicate:
Pre and post increment/decrement operators in C#
Consider the following simple snippet:
int x = 0;
int y = ++x + 1; // forks fine, gives y 2 (no doubt :) )
int x = 0;
int y = ++x++; // Error: The operand of an increment or decrement operator must be a variable, property or indexer.
It's obvious that mixing pre/post increments or decrements in the same statement is not a desirable feature for compilers.
But
- Isn't, in fact,
++x++
the same as++x + 1
? Even taking into account all the subtleties Eric Lippert uncovers here. They're all about the behavior not the relations with the operand and moreover the message the CSC outputs. - Isn't, in fact,
x
is a variable? Like, in++x + 1
that builds fine, the operand is the samex
. And it similarly operates over pre-increment operator ++. So this is still being a useful restriction seems a bit odd with its compiler error. Wouldn't it be more meaningful to output, say, "Pre-Increment and Post-increment operators can't be applied simultaneously? - And do you guys know any hidden compiler-perspective reason for this restriction, rather than the code usability one?