0Pricing
C# Academy · Lesson

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

  1. Arithmetic and Assignment Operators
  2. Comparison and Logical Operators
  3. Bitwise and Shift Operators
  4. Operator Precedence and Associativity
← Back to C# Academy