O'Reilly logo

Learning Visual Basic .NET 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

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

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