8.17. Operator Precedence

When an expression contains multiple operators, the precedence of the operators controls the order in which the operators are evaluated. For example, in a simple expression such as x + y * z, the * operator gets precedence, and hence the expression is evaluated as x + (y * z).

Except for the assignment operators, all binary operators are left-associative, meaning that operations are performed from left to right. For example, x + y + z is evaluated as (x + y) + z. The assignment operators and the conditional operator (?:) are right-associative, meaning that operations are performed from right to left. For example, x = y = z is evaluated as x = (y = z).

Precedence and associativity can be controlled using parentheses. ...

Get .NET for Java Developers: Migrating to C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.