Pre/Post Operators

The increment (++) and decrement (--) operators have two usages. That is, they can be used for both pre-operation and post-operation evaluation. When the operators appear before the variable, the operation takes place before the variable is evaluated. When they follow the variable, the operation takes place after the variable has been evaluated. Take a look at the following statements:

int i = 10;
Console.WriteLine( i++ ); //prints 10, then increments i to 11
Console.WriteLine( ++i ); //increments i to 12 and prints 12

When the value of i is sent to the WriteLine method the first time, i is evaluated to 10 and that value is passed to the WriteLine method. The variable i is then incremented to 11. On the next line, because ...

Get Microsoft® Visual C#® .NET 2003 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.