Postfix and Prefix Increment and Decrement Operators

Conceptually closely related to compound assignment with the + and - binary operators are the postfix and prefix increment and decrement operators. In essence, they abbreviate simple operators as “plus one” and “minus one” into succinct syntax, respectively as ++ and --. One common use can be found in the context of for loops, which are discussed in the Chapter 7, “Simple Control Flow.” Here is the typical pattern to create a loop that will execute the loop body 10 times:

for (int i = 0; i < 10; i++){    // Use integer value i if desired.}

A for loop consists of four parts: an initializer (here int i = 0), a condition (i < 10), an iterator (i++), and a loop body (the part in between curly braces). ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.