<  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 ( / ).


It is preferable to use parentheses to clarify how an operation is to be performed rather than relying on the precedence and associativity of operators. It is easy to forget the precedence order of the operators!

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




x ^ y

Unary plus

Unary minus

+ x

“ x



x * y

x / y

Integer division

x \ y

Integer remainder

x Mod y



x + y

x “ y


x & y


x << y

x >> y



Less than

Greater than

Less than or equal to

Greater than or equal to

Type equality

Reference equality

String matching

x = y

x <> y

x < y

x > y

x <= y

x >= y

TypeOf x Is y

x Is y

x Like y

Bitwise NOT

Not x

Bitwise AND

Logical AND

x And y

x AndAlso y

Bitwise OR

Logical OR

Bitwise XOR

x Or y

x OrElse y

x Xor y

 <  Day Day Up  >  

The Visual Basic .NET Programming Language
The Visual Basic .NET Programming Language
ISBN: 0321169514
EAN: 2147483647
Year: 2004
Pages: 173
Authors: Paul Vick

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: