VB.Net 中可用的数据类型
VB.Net 提供了广泛的数据类型。下表显示了所有可用的数据类型-
数据类型 |
存储分配 |
取值范围 |
Boolean |
依赖于实现平台 |
True 或 False |
Byte |
1 byte |
0 至 255 (无符号) |
Char |
2 bytes |
0 至 65535 (无符号) |
Date |
8 bytes |
0:00:00 (midnight) on January 1, 0001 至 11:59:59 PM on December 31, 9999 |
Decimal |
16 bytes |
0 至 +/-79,228,162,514,264,337,593,543,950,335 (+/-7.9...E+28) with no decimal point; 0 至 +/-7.9228162514264337593543950335 with 28 places to the right of the decimal |
Double |
8 bytes |
负值 -1.79769313486231570E+308 至 -4.94065645841246544E-324 ; 正值 4.94065645841246544E-324 至 1.79769313486231570E+308 |
Integer |
4 bytes |
-2,147,483,648 至 2,147,483,647 (有符号) |
Long |
8 bytes |
-9,223,372,036,854,775,808 至 9,223,372,036,854,775,807(有符号) |
Object |
在32位平台上 4 bytes ;在64位平台上 8 bytes |
Any type can be stored in a variable of type Object |
SByte |
1 byte |
-128 至 127 (有符号) |
Short |
2 bytes |
-32,768 至 32,767 (有符号) |
Single |
4 bytes |
负值 -3.4028235E+38 至 -1.401298E-45 ; 正值 1.401298E-45 至 3.4028235E+38 |
String |
依赖于实现平台 |
0 大概 20亿个 Unicode 字符 |
UInteger |
4 bytes |
0 至 4,294,967,295 (无符号) |
ULong |
8 bytes |
0 至 18,446,744,073,709,551,615 (无符号) |
User-Defined |
依赖于实现平台 |
结构的每个成员都有一个范围,该范围由其数据类型确定,并且与其他成员的范围无关 |
UShort |
2 bytes |
0 至 65,535 (无符号) |
例
以下示例演示了某些类型的法-
Module DataTypes
Sub Main()
Dim b As Byte
Dim n As Integer
Dim si As Single
Dim d As Double
Dim da As Date
Dim c As Char
Dim s As String
Dim bl As Boolean
b = 1
n = 1234567
si = 0.12345678901234566
d = 0.12345678901234566
da = Today
c = "U"c
s = "Me"
If ScriptEngine = "VB" Then
bl = True
Else
bl = False
End If
If bl Then
'the oath taking
Console.Write(c & " and," & s & vbCrLf)
Console.WriteLine("declaring on the day of: {0}", da)
Console.WriteLine("We will learn VB.Net seriously")
Console.WriteLine("Lets see what happens to the floating point variables:")
Console.WriteLine("The Single: {0}, The Double: {1}", si, d)
End If
Console.ReadKey()
End Sub
End Module
尝试一下
编译并执行上述代码后,将产生以下结果-
U and,Me
declaring on the day of: 09/27/2020 00:00:00
We will learn VB.Net seriously
Lets see what happens to the floating point variables:
The Single: 0.1234568, The Double: 0.123456789012346