Combination Assignment Operators

The following assignment, found in line 18 of Listing 9.6

height = height + 100;

as you know, increments the variable height by 100. Frequently, and in particular in connection with iteration statements, variables are incremented with a specific amount. C# offers a condensed way of writing this type of assignment through the plus-equals (+=) operator. It allows us to express the previous assignment statement as

where the left operand is added to the right operand (step 1) and the result is then assigned to the left operand (step 2).

C# contains five combination assignment operators, one for each of the binary ...

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