Freigeben über


Operators and Expressions in Visual Basic

An operator is a code element that performs an operation on one or more code elements that hold values. Value elements include variables, constants, literals, properties, returns from Function and Operator procedures, and expressions.

An expression is a series of value elements combined with operators, which yields a new value. The operators act on the value elements by performing calculations, comparisons, or other operations.

Types of Operators

Visual Basic provides the following types of operators:

The value elements that are combined with an operator are called operands of that operator. Operators combined with value elements form expressions, except for the assignment operator, which forms a statement. For more information, see Statements in Visual Basic.

Evaluation of Expressions

The end result of an expression represents a value, which is typically of a familiar data type such as Boolean, String, or a numeric type.

The following are examples of expressions.

5 + 4

' The preceding expression evaluates to 9.

15 * System.Math.Sqrt(9) + x

' The preceding expression evaluates to 45 plus the value of x.

"Concat" & "ena" & "tion"

' The preceding expression evaluates to "Concatenation".

763 < 23

' The preceding expression evaluates to False.

Several operators can perform actions in a single expression or statement, as the following example illustrates.

x = 45 + y * z ^ 2

In the preceding example, Visual Basic performs the operations in the expression on the right side of the assignment operator (=), then assigns the resulting value to the variable x on the left. There is no practical limit to the number of operators that can be combined into an expression, but an understanding of Operator Precedence in Visual Basic is necessary to ensure that you get the results you expect.

For more information and examples, see Operator Overloading in Visual Basic 2005.

See Also

Concepts

Efficient Combination of Operators (Visual Basic)

Other Resources

Operators (Visual Basic)

Statements (Visual Basic)