Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
This chapter is from the book

3.10 Assignment Operators

Visual Basic .NET provides several assignment operators for abbreviating assignment statements. For example, the statement

value = value + 3 

can be abbreviated with the addition assignment operator (+=) as

value += 3 

The += operator adds the value of the right operand to the value of the left operand and stores the result in the left operand's variable. Any statement of the form

variable = variable operator expression

where operator is one of the binary operators +, -, *, ^, &, / or \, can be written in the form

variable operator= expression

Figure 3.2 lists the arithmetic assignment operators and provides sample expressions using these operators and corresponding explanations.

Although the symbols =, +=, -=, *=, /=, \=, ^= and &= are operators, we do not include them in operator-precedence tables. When an assignment statement is evaluated, the expression to the right of the operator always is evaluated first and subsequently assigned to the variable on the left. Unlike Visual Basic's other operators, the assignment operators can occur only once in a statement.

Figure 3.2Fig. 3.2 Assignment operators.

  • + Share This
  • 🔖 Save To Your Account