Visual Basic Language Reference  

Operator Precedence in Visual Basic

When several operations occur in an expression, each part is evaluated and resolved in a predetermined order called operator precedence.

When expressions contain operators from more than one category, they are evaluated according to the following rules. The arithmetic and concatenation operators have an order of precedence that is described below, and all have higher precedence than the comparison and logical operators. Comparison operators have higher precedence than the logical operators, but lower precedence than the arithmetic and concatenation operators. All comparison operators have equal precedence; that is, they are evaluated in the order, left to right, in which they appear. Arithmetic, concatenation and logical/bitwise Operators are evaluated in the following order of precedence:

Arithmetic/Concatenation Operators

Exponentiation (^)

Negation ()

Multiplication and division (*, /)

Integer division (\)

Modulus arithmetic (Mod)

Addition and subtraction (+, ), String concatenation (+)

String concatenation (&)

Comparison Operators

Equality (=)

Inequality (<>)

Less than, greater than (<,>)

Greater than or equal to (>=)

Less than or equal to (<=)

Like

Is

TypeOf...Is

Logical/Bitwise Operators

Negation (Not)

Conjunction (And, AndAlso)

Disjunction (Or, OrElse, Xor)

When multiplication and division occur together in an expression, each operation is evaluated as it occurs from left to right. When addition and subtraction occur together in an expression, each operation is evaluated in order of appearance from left to right. Parentheses can be used to override the order of precedence and force some parts of an expression to be evaluated before others. Operations within parentheses are always performed before those outside. Within parentheses, however, operator precedence is maintained.

The string concatenation operator (&) is not an arithmetic operator, but in precedence, it does follow all arithmetic operators and precede all comparison operators.

The Is operator is an object reference comparison operator. It does not compare objects or their values; it checks only to determine if two object references refer to the same object.

See Also

= Operator | Is Operator | Like Operator | Operators Listed by Functionality | Operators