< Day Day Up > |
All operators in Visual Basic .NET have a certain precedence that determines in what order operations are performed if an expression has more than one operator. An operator with higher precedence than another operator will be evaluated first. Operators with equal precedence will be evaluated from left to right. (Thus, operators are left-associative. ) For example, the multiplication operator ( * ) has a higher precedence than the addition operator ( + ). Therefore, the result of the expression 2 * 4 + 2 is 10 and not 12 . This is because the expression is evaluated as (2 * 4) + 2 , not 2 * (4 + 2) . The expression 2 * 4 / 2 is evaluated as (2 * 4) / 2 instead of 2 * (4 / 2) because the multiplication operator ( * ) has a precedence equal to the division operator ( / ).
Table 5-1 lists the operators in order of precedence. Each box represents a different level of precedence, from highest to lowest . All operators at the same level have the same precedence. Table 5-1. Operator Precedence
|
< Day Day Up > |