C# can combine numeric values with arithmetic operators.
Common operators include:
+ addition
- subtraction
* multiplication
/ division
% remainder
A simple soccer score update can be written as:
team1.score = team1.score + 1;
The right side is an expression.
C# evaluates the expression, then assigns the result back to the field.
For:
team1.score = team1.score + 1;
read:
team1.score;team1.score.If the score begins at 2, the new state becomes 3.
Consider:
team1.points = 2 + 3 * 4;
The multiplication is evaluated before the addition.
The result is:
2 + 12 = 14
Parentheses can make the intended grouping explicit:
team1.points = (2 + 3) * 4;
Now the result is:
5 * 4 = 20
An expression involving int values behaves according to integer arithmetic.
A calculation that needs fractional results may require a compatible numeric type.
Detailed numeric conversion appears later in PC1.
For now, use expressions whose operand types fit the current fields.
% Produces the RemainderFor:
7 % 2
the result is:
1
because dividing 7 by 2 leaves a remainder of 1.
This operator becomes useful in later logic and repetition examples.
The expression calculates a value.
The assignment changes the object's state.
Keep the two parts visible:
expression → produces value
assignment → stores value
That distinction helps when predicting what the program will do.