Compartilhar via


Como: Armazenar dados de tipo desconhecido em uma variável (Visual Basic)

A variable holds pointers to data if you declare it to be of data type Object.

A variable of the Tipo de dados Object can hold a pointer to a value of any data type. This includes both value types, such as Integer, Boolean, and structure instances, and reference types, which are instances of objects created from classes such as String, Form, and array instances.

Desempenho. A vantagem de Object tipo de dados é que você pode usá-lo para apontar para dados de tipo de dados. The disadvantage is that you incur extra operations that take more execution time and make your application perform slower. If you use an Object variable for value types, you incur boxing and unboxing. If you use it for reference types, you incur late binding.

You should use the Object data type when your variable needs to hold different data types at different times, or when you do not know at compile time what data type or types your variable might hold.

To hold data of unknown type in a variable

  1. Declare the variable with a Instrução Dim (Visual Basic).

  2. Follow the variable name with an As clause.

  3. Follow the As keyword with the Object keyword.

Consulte também

Referência

Resumo de tipo de dados (Visual Basic)

Tipo de dados único (Visual Basic)

Tipo de dados Object

Conceitos

Tipos de dados no Visual Basic

Caracteres de tipo (Visual Basic)

Outros recursos

Tipos de dados elementares (Visual Basic)

Implementação de tipos de dados (Visual Basic)