description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: Short data type (Visual Basic) |
Short Data Type |
01/31/2018 |
|
|
65fcbcf3-a841-400e-885e-301497729a8b |
Holds signed 16-bit (2-byte) integers that range in value from -32,768 through 32,767.
Use the Short
data type to contain integer values that do not require the full data width of Integer
. In some cases, the common language runtime can pack your Short
variables closely together and save memory consumption.
The default value of Short
is 0.
You can declare and initialize a Short
variable by assigning it a decimal literal, a hexadecimal literal, an octal literal, or (starting with Visual Basic 2017) a binary literal. If the integer literal is outside the range of Short
(that is, if it is less than xref:System.Int16.MinValue?displayProperty=nameWithType or greater than xref:System.Int16.MaxValue?displayProperty=nameWithType, a compilation error occurs.
In the following example, integers equal to 1,034 that are represented as decimal, hexadecimal, and binary literals are implicitly converted from Integer to Short
values.
[!code-vbShort]
Note
You use the prefix &h
or &H
to denote a hexadecimal literal, the prefix &b
or &B
to denote a binary literal, and the prefix &o
or &O
to denote an octal literal. Decimal literals have no prefix.
Starting with Visual Basic 2017, you can also use the underscore character, _
, as a digit separator to enhance readability, as the following example shows.
[!code-vbShort]
Starting with Visual Basic 15.5, you can also use the underscore character (_
) as a leading separator between the prefix and the hexadecimal, binary, or octal digits. For example:
Dim number As Short = &H_3264
[!INCLUDE supporting-underscores]
Numeric literals can also include the S
type character to denote the Short
data type, as the following example shows.
Dim number = &H_3264S
-
Widening. The
Short
data type widens toInteger
,Long
,Decimal
,Single
, orDouble
. This means you can convertShort
to any one of these types without encountering a xref:System.OverflowException?displayProperty=nameWithType error. -
Type Characters. Appending the literal type character
S
to a literal forces it to theShort
data type.Short
has no identifier type character. -
Framework Type. The corresponding type in the .NET Framework is the xref:System.Int16?displayProperty=nameWithType structure.
- xref:System.Int16?displayProperty=nameWithType
- Data Types
- Type Conversion Functions
- Conversion Summary
- Integer Data Type
- Long Data Type
- Efficient Use of Data Types