Compartilhar via


Uso eficiente de tipos de dados (Visual Basic)

Undeclared variables and variables declared without a data type are assigned the Object data type. This makes it easy to write programs quickly, but it can cause them to execute more slowly.

Strong Typing

Specifying data types for all your variables is known as strong typing. Using strong typing has several advantages:

  • It enables IntelliSense® support for your variables. This allows you to see their properties and other members as you type in the code.

  • It takes advantage of compiler type checking. This catches statements that can fail at run time due to errors such as overflow. It also catches calls to methods on objects that do not support them.

  • It results in faster execution of your code.

Most Efficient Data Types

For variables that never contain fractions, the integral data types are more efficient than the nonintegral types. In Visual Basic, Integer and UInteger are the most efficient numeric types.

For fractional numbers, Double is the most efficient data type, because the processors on current platforms perform floating-point operations in double precision. However, operations with Double are not as fast as with the integral types such as Integer.

Specifying Data Type

Use the Instrução Dim (Visual Basic) to declare a variable of a specific type. You can simultaneously specify its access level by using the Público (Visual Basic), Protegido (Visual Basic), Friend (Visual Basic), or Private (Visual Basic) keyword, as in the following example.

Private x As Double
Protected s As String

Character Conversion

The AscW and ChrW functions operate in Unicode. You should use them in preference to Asc and Chr, which must translate into and out of Unicode.

Consulte também

Referência

Asc

AscW

Chr

ChrW

Conceitos

Tipos de dados no Visual Basic

Programação Sem-Tipos no Visual Basic

Declaração explícita e implícita (Visual Basic)

Verificação de Tipo no Visual Basic

Objeto como o tipo de dados Universal (Visual Basic)

Tipos de dados numéricos (Visual Basic)

Declaração de variável no Visual Basic

Outros recursos

Usando o IntelliSense