5.8. Operator PrecedenceIf you include more than one operator in a single line of code, you need to know the order in which VB will evaluate them. Otherwise, the results may be completely different from what you intended. For instance, the following statement: x = 5 + 3 * 7 could be interpreted as: x = (5 + 3) * 7 ' --> 56 or as: x = 5 + (3 * 7) ' --> 26 The rule that defines the order in which a language processes operators is known as the order of precedence . If the order of precedence results in operations being evaluated in an order other than the intended one, you can explicitly override the order of precedence through the use of parentheses. Indeed, complex (or even relatively simple) expressions should include parentheses to avoid any compiler misinterpretation or human confusion. (By the way, the example, once parentheses are removed, evaluates to 26.) When multiple operators appear at the same level of evaluation (that is, they are not subgrouped with parentheses), they are processed in a specific order of precedence. In some instances, multiple operators appear at the same level of precedence (as are * and /). They are treated as equals as far as precedence is concerned. The following list indicates the order of precedence in evaluation, from first to last.
Since the AddressOf and GetType operators are implemented like functions, they fall outside of the order of precedence rules for operators. If multiple operators of the same order of precedence appear at the same level of evaluation, they are processed from left to right. |