Arithmetic Shortcuts
Part of the Fundamentals section of Coddy's C# journey. Lesson 19 of 70.
C# created a cool shortcut for self-arithmetic operations.
For example instead of writing:
int a = 5;
a = a + 3; // a holds 8We can simplify it by writing +=:
int a = 5;
a += 3; // a holds 8The += is adding to a itself the value 3
This operation is valid for all arithmetic operations:
| Operator | Shortcut |
|---|---|
| + | += |
| - | -= |
| * | *= |
| / | /= |
| % | %= |
Challenge
Beginnercount starts at 0, and the line below your code prints it.
Your task is to add the following operations, in this order:
- Add
4tocount - Multiply
countby2 - Subtract
1fromcount
Use the arithmetic shortcuts to do so!
Try it yourself
// Type your code below
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic Shortcuts5Operators Part 2
Comparison OperatorsLogical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Practice on your own: Online C# compiler