更新:2007 年 11 月
请记住,数组的数据类型与其元素的数据类型根本是两回事。可以通过几种方法确定数组或其元素的数据类型。
- 可以对变量调用 Object.GetType 方法,从而得到包含该变量的运行时类型的 Type 对象。Type 对象在其属性和方法中保存了大量信息。 
- 可以将变量传递给 TypeName 函数 (Visual Basic),从而得到包含运行时类型的名称的 String。 
- 可以将变量传递给 VarType 函数 (Visual Basic),从而得到表示变量的类型分类的 VariantType 值。 
确定数组的数据类型
- 对数组名称调用 TypeName。数组名称后面不要跟括号,这是因为要请求的是数组本身的类型。 - Dim thisTwoDimArray(,) As Integer = New Integer(9, 9) {} MsgBox("Type of thisTwoDimArray is " & TypeName(thisTwoDimArray))- MsgBox 调用显示“Type of thisTwoDimArray is Integer(,)”,显示的内容说明了元素类型和维数。它不显示各维的当前长度,这是因为长度不属于数组数据类型。 
确定数组元素的数据类型
- 选择一个现有元素并对该元素调用 TypeName。 - Dim thisTwoDimArray(,) As Integer = New Integer(9, 9) {} MsgBox("Type of thisTwoDimArray(0, 0) is " & TypeName(thisTwoDimArray(0, 0)))- MsgBox 调用显示“Type of thisTwoDimArray(0, 0) is Integer”。 - 元素数据类型是数组的数据类型的一部分。因此,即使是使用赋值语句或 ReDim 语句,也不能更改元素的数据类型。