Previous topicNext topic
Help > 开发指南 > 编程基础 > VB编程基础 >
数据类型

数据类型指用于声明不同类型的变量或函数的扩展系统。 变量的类型确定它在存储中占用多少空间以及如何解释存储的位模式。

VB.Net中提供的数据类型

VB.Net提供了多种数据类型。下表显示的所有数据类型可用的:

数据类型 存储分配 值范围
Boolean 取决于实施平台
Byte 1个字节 0到255(无符号)
Char 2个字节 0?65535(无符号)
Date 8个字节 00:00:00(午夜),时间为0001年12月31日11时31分至晚上11:59:59
Decimal 16字节 0至+/- 79,228,162,514,264,337,593,543,950,335(+/- 7.9 ... E + 28),没有小数点; 0到+/- 7.9228162514264337593543950335,其中小数点右边有28个位
Double 8个字节

-1.79769313486231570E + 308至-4.94065645841246544E-324,对于负值

4.94065645841246544E-324至1.79769313486231570E + 308,对于正值

Integer 4个字节 -2,147,483,648至2,147,483,647(有符号)
Long 8个字节 -9,223,372,036,854,775,808至9,223,372,036,854,775,807(签字)
Object

在32位平台上的4个字节

在64位平台8字节

任何类型都可以存储在Object类型的变量中
SByte 1个字节 -128至127(签字)
Short 2个字节 -32,768至32,767(签字)
Single 4个字节

-3.4028235E + 38至-1.401298E-45为负值;

1.401298E-45至3.4028235E + 38正值

String 取决于实施平台 0到大约20亿个Unicode字符
UInteger 4个字节 0至4294967295(无符号)
ULONG 8个字节 0至18,446,744,073,709,551,615(签名)
User-Defined 取决于实施平台 结构的每个成员具有由其数据类型确定的范围并且独立于其他成员的范围
UShort 2个字节 0至65,535(无符号)

 

示例

下面示例演示使用一些类型

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
    Proj.MsgDebug.Add(c & " and," & s & vbCrLf)
    Proj.MsgDebug.Add(String.Format("declaring on the day of: {0}", da))
    Proj.MsgDebug.Add("We will learn VB.Net seriously")
    Proj.MsgDebug.Add("Lets see what happens to the floating point variables:")
    Proj.MsgDebug.Add(String.Format("The Single: {0}, The Double: {1}", si, d))
End If

当上述代码被编译和执行时,它产生了以下结果:

'U And,Me
'declaring On the day Of: 2022-07-06 0: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