O'Reilly logo

Programming Visual Basic .NET, Second Edition by Jesse Liberty

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

An operator is a symbol (e.g., =, +, >, &) that causes VB.NET to take an action. That action might be an assignment of a value to a variable, the addition of two values, a comparison of two values, concatenation of strings, etc.

In the previous sections, you’ve seen a number of operators at work. For example, the assignment operator (=) has been used to assign a value to a variable:

Dim myVariable As Integer
myVariable = 15

In the code shown above, the value 15 is assigned to the Integer variable myVariable. In the section on branching you saw more sophisticated operators, such as the greater-than comparison operator (>) used to compare two values:

If valueOne > valueTwo Then

The preceding If statement compares valueOne with valueTwo; if the former is larger than the latter, the test evaluates true, and the If statement executes.

The following sections will consider many of the operators used in VB.NET in some detail.

Mathematical Operators

VB.NET uses seven mathematical operators: five for standard calculations (+, -, *, /, and \), a sixth to return the remainder when dividing integers (Mod), and a seventh for exponential operations (^). The following sections consider the use of these operators.

Simple arithmetic operators (+, -, *, /, \)

VB.NET offers five operators for simple arithmetic: the addition (+), subtraction (-), and multiplication (*) operators work as you might expect. Adding two numbers returns their sum, subtracting returns their difference, and ...

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