Lesson 05 of 30
Operators and Expressions
C# in Visual Studio 2026 — a hands-on guide for developers at every level.
Arithmetic Operators
| Operator | Meaning | Example | Result |
|---|---|---|---|
+ | Addition | 10 + 3 | 13 |
- | Subtraction | 10 - 3 | 7 |
* | Multiplication | 10 * 3 | 30 |
/ | Division | 10 / 3 | 3 (integer division) |
% | Modulus (remainder) | 10 % 3 | 1 |
int a = 10, b = 3;
Console.WriteLine(a / b); // 3 (integer division truncates)
Console.WriteLine((double)a / b); // 3.333... (cast to double first)
Console.WriteLine(a % b); // 1
Assignment and Compound Operators
int x = 5;
x += 3; // x = x + 3 → 8
x -= 2; // x = x - 2 → 6
x *= 4; // x = x * 4 → 24
x /= 6; // x = x / 6 → 4
x++; // x = x + 1 → 5
x--; // x = x - 1 → 4
Comparison Operators
int n = 10;
Console.WriteLine(n == 10); // True
Console.WriteLine(n != 5); // True
Console.WriteLine(n > 8); // True
Console.WriteLine(n <= 10); // True
Logical Operators
bool a = true, b = false;
Console.WriteLine(a && b); // False — AND
Console.WriteLine(a || b); // True — OR
Console.WriteLine(!a); // False — NOT
The Math Class
Console.WriteLine(Math.Abs(-7)); // 7
Console.WriteLine(Math.Pow(2, 10)); // 1024
Console.WriteLine(Math.Sqrt(144)); // 12
Console.WriteLine(Math.Round(3.567, 2)); // 3.57
Console.WriteLine(Math.Max(10, 20)); // 20