Operator precedence defines how an expression evaluates when several operators are present.

C# has specific rules that determine the order of evaluation.

The easiest one to remember is that multiplication and division happen before addition and subtraction.

Programmers often forget the other precedence rules,

so you should use parentheses to make the order of evaluation explicit.

For example:

The code has a very different meaning from the same statement with a particular grouping of parentheses:

Points:

C# looks for parentheses to give high priority.

Then it looks for multiplication and division.

Then addition and subtraction.

If some operations have same priority, C# follows left to right execution.

..

C# has specific rules that determine the order of evaluation.

The easiest one to remember is that multiplication and division happen before addition and subtraction.

Programmers often forget the other precedence rules,

so you should use parentheses to make the order of evaluation explicit.

For example:

a = x + y - 2/2 + z;

The code has a very different meaning from the same statement with a particular grouping of parentheses:

a = x + (y - 2)/(2 + z);

Points:

C# looks for parentheses to give high priority.

Then it looks for multiplication and division.

Then addition and subtraction.

If some operations have same priority, C# follows left to right execution.

..