Operator Precedence

noun

say it: “OP-er-ay-ter PRES-ih-dens” /ˈɒpəreɪtər ˈprɛsɪdəns/

The order in which C# works out the parts of an expression, such as multiplication before addition.

What is Operator Precedence in C#?

Operator Precedence — The order C# works out an expression in: parentheses first, then *, / and %, then + and -, left to right within each level. Add parentheses whenever you want a different order, or just to make it clear.

Console.WriteLine(10 + 2 * 3);   // 16
Console.WriteLine((10 + 2) * 3); // 36

In a sentence

  • “Because of operator precedence, 10 + 2 * 3 is 16, not 36.”

Level: Novice · More C# terms at this level

Updated