Compartilhar via


Como: Declarar uma Variável Objeto e Atribuir um Objeto a ela no Visual Basic

You declare a variable of the Tipo de dados Object by specifying As Object in a Instrução Dim (Visual Basic). You assign an object to such a variable by placing the object after the equal sign (=) in an assignment statement or initialization clause.

Exemplo

The following example declares an Object variable and assigns the current instance to it.

Dim thisObject As Object
thisObject = "This is an Object"

You can combine the declaration and assignment by initializing the variable as part of its declaration. The following example is equivalent to the preceding example.

Dim thisObject As Object = "This is an Object"

Compilando o código

This example requires:

  • A reference to the System namespace.

  • A class, structure, or module in which to put the Dim statement.

  • A procedure in which to put the assignment statement.

Consulte também

Referência

Tipo de dados Object

Instrução Dim (Visual Basic)

Opção declaração estrito

Conceitos

Declaração de variável no Visual Basic

Variáveis de objeto no Visual Basic

Declaração de variável de objeto (Visual Basic)

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