如何:确定一维数组的长度
更新:2007 年 11 月
数组的 GetLength 方法返回指定维的长度。
确定数组中某一维的长度
对数组名称调用 GetLength。提供要获得其长度的维,作为 GetLength 的参数。注意维参数是从零开始的。
Dim sampleTripleArray(,,) As Short = New Short(2, 3, 4) {} MsgBox("Dimension lengths of sampleTripleArray are " & CStr(sampleTripleArray.GetLength(0)) _ & ", " & CStr(sampleTripleArray.GetLength(1)) & ", " & CStr(sampleTripleArray.GetLength(2)))
MsgBox 调用显示“Dimension lengths of sampleTripleArray are 3, 4, 5”。
每个维的最小索引值总是为 0,而 GetUpperBound 方法返回维的最大索引值。对于每个维,GetLength 的返回值都比 GetUpperBound 的返回值大 1。与 GetLength 一样,为 GetUpperBound 指定的维也是从零开始的。
可以使用数组的 Length 属性确定其总长度。
可以通过更改单个维的大小来更改数组的总大小。但是,不能更改秩(维数)。