Operator Precedence and Associativity
Understand evaluation order and use parentheses.
Why Precedence Matters
When an expression mixes operators, C# decides the order using precedence. Higher-precedence operators bind tighter and run first.
using System;
class Program {
static void Main() {
Console.WriteLine(2 + 3 * 4);
}
}Multiplicative Before Additive
* / % have higher precedence than + -, so they execute first, just like in math class.
using System;
class Program {
static void Main() {
Console.WriteLine(10 - 2 * 3);
Console.WriteLine(20 / 4 + 1);
}
}All lessons in this course
- Arithmetic and Assignment Operators
- Comparison and Logical Operators
- Bitwise and Shift Operators
- Operator Precedence and Associativity