Chapter 7. Operators

An operator is a symbol (e.g., =, +, >, etc.) 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, or a comparison of two values, etc.

In the previous chapters, you’ve seen a number of operators at work. For example, in Chapter 5 you saw the assignment operator used. The single equal sign (=) is used to assign a value to a variable, in this case the value 15 to the Integer variable myVariable:

Dim myVariable As Integer = 15

In Chapter 6, 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.

This chapter will consider many of the operators used in VB.NET in some detail.

The Assignment Operator (=)

The assignment operator causes the operand on the left side of the operator to have its value changed to whatever is on the right side of the operator. The following expression assigns the value 15 to myVariable:

Dim myVariable As Integer = 15

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 Arithmetical Operators ...

Get Learning Visual Basic .NET now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.