Associativity

If you look at the precedence of the multiplication and division operators in Table 7.1, you will find them to have equal precedence. Now, consider the following expression:

How does C# determine which operator is applied first? It cannot get any help from the precedence rules because the two operators have identical precedence. C# then resorts to the rules of associativity. An operator can either have left-to-right or right-to-left associativity. When two operators (such as (/) and (*)) with the same precedence can be applied to the same operand (such as 5 in the previous expression), left-to-right associativity will cause the leftmost ...

Get C# Primer Plus 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.