AllTheTimeWorld.com

csharp arithmeticOrder of operations

Order of operations

Explains how arithmetic expressions with more than 1 operator are evaluated

Order of operations

Explains how arithmetic expressions with more than 1 operator are evaluated

A statement can perform more than one arithmetic operation.
If there is more than one arithmetic operation in a statement, they are executed according to the level of the operators:
Parenthesis take precedence over all other operators; multiplication and division take precedence over mod, mod takes precedence over addition and subtraction.

Evaluate an expression in the following order:

  1. Anything inside parenthesis, including functions, is done first: working from the inner-most parenthesis out;
  2. Multiplication and division (*, /) are performed from left to right;
  3. % is performed from left to right;
  4. Addition and subtraction ( + and -), are performed from left to right.