The statement
x++;
is exactly equivalent to
x = x + 1;
except that x
is evaluated only once (which makes a difference if it is an expression involving property getters).
The difference between the following two:
DoSomething(x++); // notice x first, then ++
DoSomething(++x); // notice ++ first, then x
Is that in the first one, the method DoSomething
will see the previous value of x
before it was incremented. In the second one, it will see the new (incremented) value.
For more information, see C# Operators on MSDN.
It is possible to declare a custom ++
operator for your own classes, in which case the operator can do something different. If you want to define your own ++
operator, see Operator Overloading Tutorial on MSDN.