Visual Basic 中数组的大小? [英] Size of array in Visual Basic?
本文介绍了Visual Basic 中数组的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在 VB 中尝试过这段代码:
I've tried this code in VB:
Dim a(1) As Byte
Console.WriteLine(a.Length)
输出为2".有人知道为什么吗?
The output is "2". Anyone any idea why?
推荐答案
如果你习惯了 C/C++/C# 语言,你会习惯于在声明一个数组时使用元素数量 在数组中.
If you are used to C/C++/C# languages you are used that when declaring an array to initialize it with the number of elements in the array.
C# : byte a[] = new byte[1]
将声明一个包含 1 个元素的字节数组 (upperBound = 0)
will declare a byte array with 1 element (upperBound = 0)
在 VB 中行为不同,其中声明数组时,初始化中使用的参数表示数组的 UpperBound.
The behavior is different in VB where, when declaring an array the parameter used in initialization represents the UpperBound of the array.
VB.NET: Dim a(1) As Byte
将声明一个包含 2 个元素的字节数组(upperBound = 1)
will declare a byte array with 2 elements (upperBound = 1)
这篇关于Visual Basic 中数组的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文