Share via


Operador = (Visual Basic)

Assigns a value to a variable or property.

variableorproperty = value

Parts

  • variableorproperty
    Any writable variable or any property.

  • value
    Any literal, constant, or expression.

Comentários

The element on the left side of the equal sign (=) can be a simple scalar variable, a property, or an element of an array. The variable or property cannot be ReadOnly (Visual Basic). The = operator assigns the value on its right to the variable or property on its left.

ObservaçãoObservação

The = operator is also used as a comparison operator. For details, see Operadores de comparação (Visual Basic).

Overloading

The = operator can be overloaded only as a relational comparison operator, not as an assignment operator. For more information, see Procedimentos de operador (Visual Basic).

Exemplo

The following example demonstrates the assignment operator. The value on the right is assigned to the variable on the left.

Dim testInt As Integer
Dim testString As String
Dim testButton As System.Windows.Forms.Button
Dim testObject As Object
testInt = 42
testString = "This is an example of a string literal."
testButton = New System.Windows.Forms.Button()
testObject = testInt
testObject = testString
testObject = testButton

Consulte também

Referência

Operador &= (Visual Basic)

Operador *= (Visual Basic)

Operador += (Visual Basic)

Operador -= (Visual Basic)

Operador /= (Visual Basic)

Operador \=

Operador ^= (Visual Basic)

Operadores de comparação (Visual Basic)

ReadOnly (Visual Basic)

Conceitos

Inferência de tipo de variável local (Visual Basic)

Outros recursos

Instruções no Visual Basic