Pre- and Post-Increment/Decrement

The increment and decrement operators are similar to assignments with regard to their usual treatment as statements. Useful for their side effects, they’re typically used in loop constructs, as you will see later. Let’s revisit the example from Chapter 5.

for (int i = 0; i < array.Length; i++){    // Do something}

In fact, in such a setting it doesn’t matter whether prefix or postfix syntax is used for those operators because the only difference lies in the value that gets returned and not in the side effect they’re causing. You’ll see both styles used interchangeably, with some (ancient) C/C++ developers slightly preferring the prefix notation for its performance benefit over the postfix one.

Get C# 4.0 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.