Compartilhar via


Tipos de dados de resultados de operador (Visual Basic)

Visual Basic determines the result data type of an operation based on the data types of the operands. In some cases this might be a data type with a greater range than that of either operand.

Data Type Ranges

The ranges of the relevant data types, in order from smallest to largest, are as follows:

  • Boolean — two possible values

  • SByte, Byte — 256 possible integral values

  • Short, UShort — 65,536 (6.5...E+4) possible integral values

  • Integer, UInteger — 4,294,967,296 (4.2...E+9) possible integral values

  • Long, ULong — 18,446,744,073,709,551,615 (1.8...E+19) possible integral values

  • Decimal — 1.5...E+29 possible integral values, maximum range 7.9...E+28 (absolute value)

  • Single — maximum range 3.4...E+38 (absolute value)

  • Double — maximum range 1.7...E+308 (absolute value)

For more information on Visual Basic data types, see Resumo de tipo de dados (Visual Basic).

If an operand evaluates to Nothing, the Visual Basic arithmetic operators treat it as zero.

Decimal Arithmetic

Note that the Decimal data type is neither floating-point nor integer.

Se qualquer operador de um +, –, *, /, ou Mod operação é Decimal e o outro não Single ou Double, Visual Basic amplia o outro operando em Decimal. It performs the operation in Decimal, and the result data type is Decimal.

Floating-Point Arithmetic

Visual Basic performs most floating-point arithmetic in Double, which is the most efficient data type for such operations. However, if one operand is Single and the other is not Double, Visual Basic performs the operation in Single. It widens each operand as necessary to the appropriate data type before the operation, and the result has that data type.

/ and ^ Operators

O / operador está definido somente para o Decimal, único, e Double tipos de dados. Visual Basicamplia a cada operando conforme necessário para o tipo de dados de apropriado antes da operação e o resultado tem esse tipo de dados.

The following table shows the result data types for the / operator. Note that this table is symmetric; for a given combination of operand data types, the result data type is the same regardless of the order of the operands.

Decimal

Single

Double

Any integer type

Decimal

Decimal

Single

Double

Decimal

Single

Single

Single

Double

Single

Double

Double

Double

Double

Double

Any integer type

Decimal

Single

Double

Double

O ^ operador está definido somente para o Double tipo de dados. Visual Basicamplia a cada operando conforme necessário para Double a operação e o resultado antes do tipo de dados é sempre Double.

Integer Arithmetic

The result data type of an integer operation depends on the data types of the operands. In general, Visual Basic uses the following policies for determining the result data type:

  • If both operands of a binary operator have the same data type, the result has that data type. An exception is Boolean, which is forced to Short.

  • If an unsigned operand participates with a signed operand, the result has a signed type with at least as large a range as either operand.

  • Otherwise, the result usually has the larger of the two operand data types.

Note that the result data type might not be the same as either operand data type.

ObservaçãoObservação

The result data type is not always large enough to hold all possible values resulting from the operation. An OverflowException exception can occur if the value is too large for the result data type.

Unary + and – Operators

A tabela a seguir mostra o resultado tipos de dados para os dois operadores unários, + e –.

Boolean

SByte

Byte

Short

UShort

Integer

UInteger

Long

ULong

Unary +

Short

SByte

Byte

Short

UShort

Integer

UInteger

Long

ULong

Unary –

Short

SByte

Short

Short

Integer

Integer

Long

Long

Decimal

<< and >> Operators

A tabela a seguir mostra o resultado tipos de dados para os dois bits - operadores dedeslocar , << e >>. Visual Basictrata cada bitdeslocar operador como um unário operador no seu operando esquerdo (o padrão de bit deslocamento).

Boolean

SByte

Byte

Short

UShort

Integer

UInteger

Long

ULong

<<, >>

Short

SByte

Byte

Short

UShort

Integer

UInteger

Long

ULong

If the left operand is Decimal, Single, Double, or String, Visual Basic attempts to convert it to Long before the operation, and the result data type is Long. The right operand (the number of bit positions to shift) must be Integer or a type that widens to Integer.

Binary +, –, *, and Mod Operators

A tabela a seguir mostra o resultado de tipos de dados para o binário + e – operadores e a * e Mod operadores. Note that this table is symmetric; for a given combination of operand data types, the result data type is the same regardless of the order of the operands.

Boolean

SByte

Byte

Short

UShort

Integer

UInteger

Long

ULong

Boolean

Short

SByte

Short

Short

Integer

Integer

Long

Long

Decimal

SByte

SByte

SByte

Short

Short

Integer

Integer

Long

Long

Decimal

Byte

Short

Short

Byte

Short

UShort

Integer

UInteger

Long

ULong

Short

Short

Short

Short

Short

Integer

Integer

Long

Long

Decimal

UShort

Integer

Integer

UShort

Integer

UShort

Integer

UInteger

Long

ULong

Integer

Integer

Integer

Integer

Integer

Integer

Integer

Long

Long

Decimal

UInteger

Long

Long

UInteger

Long

UInteger

Long

UInteger

Long

ULong

Long

Long

Long

Long

Long

Long

Long

Long

Long

Decimal

ULong

Decimal

Decimal

ULong

Decimal

ULong

Decimal

ULong

Decimal

ULong

\ O operador

The following table shows the result data types for the \ operator. Note that this table is symmetric; for a given combination of operand data types, the result data type is the same regardless of the order of the operands.

Boolean

SByte

Byte

Short

UShort

Integer

UInteger

Long

ULong

Boolean

Short

SByte

Short

Short

Integer

Integer

Long

Long

Long

SByte

SByte

SByte

Short

Short

Integer

Integer

Long

Long

Long

Byte

Short

Short

Byte

Short

UShort

Integer

UInteger

Long

ULong

Short

Short

Short

Short

Short

Integer

Integer

Long

Long

Long

UShort

Integer

Integer

UShort

Integer

UShort

Integer

UInteger

Long

ULong

Integer

Integer

Integer

Integer

Integer

Integer

Integer

Long

Long

Long

UInteger

Long

Long

UInteger

Long

UInteger

Long

UInteger

Long

ULong

Long

Long

Long

Long

Long

Long

Long

Long

Long

Long

ULong

Long

Long

ULong

Long

ULong

Long

ULong

Long

ULong

If either operand of the \ operator is Decimal, Single, or Double, Visual Basic attempts to convert it to Long before the operation, and the result data type is Long.

Relational and Bitwise Comparisons

O resultado de tipo de dados de uma operação de relacional (=, <>, <, >, <=, >=) é sempre BooleanTipo de dados booleanos (Visual Basic). The same is true for logical operations (And, AndAlso, Not, Or, OrElse, Xor) on Boolean operands.

The result data type of a bitwise logical operation depends on the data types of the operands. Note that AndAlso and OrElse are defined only for Boolean, and Visual Basic converts each operand as necessary to Boolean before performing the operation.

=, < >, <,> < =, e > = operadores

If both operands are Boolean, Visual Basic considers True to be less than False. If a numeric type is compared with a String, Visual Basic attempts to convert the String to Double before the operation. A Char or Date operand can be compared only with another operand of the same data type. The result data type is always Boolean.

Bitwise Not Operator

The following table shows the result data types for the bitwise Not operator.

Boolean

SByte

Byte

Short

UShort

Integer

UInteger

Long

ULong

Not

Boolean

SByte

Byte

Short

UShort

Integer

UInteger

Long

ULong

If the operand is Decimal, Single, Double, or String, Visual Basic attempts to convert it to Long before the operation, and the result data type is Long.

Bitwise And, Or, and Xor Operators

The following table shows the result data types for the bitwise And, Or, and Xor operators. Note that this table is symmetric; for a given combination of operand data types, the result data type is the same regardless of the order of the operands.

Boolean

SByte

Byte

Short

UShort

Integer

UInteger

Long

ULong

Boolean

Boolean

SByte

Short

Short

Integer

Integer

Long

Long

Long

SByte

SByte

SByte

Short

Short

Integer

Integer

Long

Long

Long

Byte

Short

Short

Byte

Short

UShort

Integer

UInteger

Long

ULong

Short

Short

Short

Short

Short

Integer

Integer

Long

Long

Long

UShort

Integer

Integer

UShort

Integer

UShort

Integer

UInteger

Long

ULong

Integer

Integer

Integer

Integer

Integer

Integer

Integer

Long

Long

Long

UInteger

Long

Long

UInteger

Long

UInteger

Long

UInteger

Long

ULong

Long

Long

Long

Long

Long

Long

Long

Long

Long

Long

ULong

Long

Long

ULong

Long

ULong

Long

ULong

Long

ULong

If an operand is Decimal, Single, Double, or String, Visual Basic attempts to convert it to Long before the operation, and the result data type is the same as if that operand had already been Long.

Miscellaneous Operators

O & operador é definido apenas para concatenação de String operandos. Visual BasicConverte cada operando conforme necessário para String a operação e o resultado antes do tipo de dados é sempre String. For the purposes of the & operator, all conversions to String are considered to be widening, even if Option Strict is On.

The Is and IsNot operators require both operands to be of a reference type. The TypeOf...Is expression requires the first operand to be of a reference type and the second operand to be the name of a data type. In all these cases the result data type is Boolean.

O Like operador é definido apenas para correspondência de padrões de String operandos. Visual Basictenta converter cada operando conforme necessário para String antes da operação. The result data type is always Boolean.

Consulte também

Referência

Resumo de tipo de dados (Visual Basic)

Precedência de operadores no Visual Basic

Operadores listados por Funcionalidade (Visual Basic)

Operadores Aritméticos (Visual Basic)

Operadores de comparação (Visual Basic)

Opção declaração estrito

Conceitos

Operadores e expressões em Visual Basic

Operadores aritméticos em Visual Basic

Operadores de Comparação em Visual Basic

Outros recursos

Operadores (Visual Basic)