O'Reilly logo

Programming Visual Basic .NET by Dave Grundgeiger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Operators and Expressions

Operators are symbols (characters or keywords) that specify operations to be performed on one or two operands (or arguments ). Operators that take one operand are called unary operators. Operators that take two operands are called binary operators. Unary operators use prefix notation , meaning that the operator precedes the operand (e.g., -5). Binary operators (except for one case) use infix notation , meaning that the operator is between the operands (e.g., 1 + 2). The TypeOf...Is operator is a binary operator that uses a special form that is neither prefix nor infix notation.

Unary Operators

Visual Basic supports the following unary operators:

+ (unary plus)

The unary plus operator takes any numeric operand. It’s not of much practical use because the value of the operation is equal to the value of the operand.

- (unary minus)

The unary minus operator takes any numeric operand (except as noted later). The value of the operation is the negative of the value of the operand. In other words, the result is calculated by subtracting the operand from zero. If the operand type is Short, Integer, or Long, and the value of the operand is the maximum negative value for that type, then applying the unary minus operator will cause a System.OverflowException error, as in the following code fragment:

Dim sh As Short = -32768
Dim i As Integer = -sh
Not (logical negation)

The logical negation operator takes a Boolean operand. The result is the logical negation of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required