Share via


Tipo de Dados Inteiro (Visual Basic)

Holds signed 32-bit (4-byte) integers that range in value from -2,147,483,648 through 2,147,483,647.

Comentários

The Integer data type provides optimal performance on a 32-bit processor. The other integral types are slower to load and store from and to memory.

The default value of Integer is 0.

Programming Tips

  • Considerações de interoperabilidade. Se você está em uma interface com componentes não são escritos para o.NET Framework, para objetos de automação ou COM exemplo, lembre-se que Integer tem uma largura de dados diferentes (16 bits) em outros ambientes. If you are passing a 16-bit argument to such a component, declare it as Short instead of Integer in your new Visual Basic code.

  • Alargamento. The Integer tipo de dados widens to Long, Decimal, Single, or Double. This means you can convert Integer to any one of these types without encountering a System.OverflowException error.

  • Tipo Caracteres. Acrescentando o caractere de tipo literal I para um literal de força para o Integer tipo de dados. Appending the identifier type character % to any identifier forces it to Integer.

  • Framework Type. O tipo correspondente na.NET Framework é o System.Int32 estrutura.

Range

If you try to set a variable of an integral type to a number outside the range for that type, an error occurs. Se você tentar defini-la como uma fração, o número será arredondado para cima ou para baixo para o valor inteiro mais próximo. Se o número é igualmente fechar dois valores de inteiro , o valor é arredondado para o mais próximo mesmo inteiro. The following example shows this.

' The valid range of an Integer variable is -2147483648 through +2147483647.
Dim k As Integer
' The following statement causes an error because the value is too large.
k = 2147483648
' The following statement sets k to 6.
k = 5.9
' The following statement sets k to 4
k = 4.5
' The following statement sets k to 6
k = 5.5

Consulte também

Referência

Resumo de tipo de dados (Visual Basic)

System.Int32

Tipo de dados Long (Visual Basic)

Tipo de dados Short (Visual Basic)

Funções de conversão de tipo (Visual Basic)

Resumo de conversão (Visual Basic)

Conceitos

Uso eficiente de tipos de dados (Visual Basic)