【发布时间】:2019-08-11 03:09:54
【问题描述】:
Dim i as Long, arr(5) As Long
for i = 1 to 6
arr(i-1) = i-1
next
console.writeLine(arr(LBound(arr)+5) + arr(UBound(arr)-2))
我知道输出是 8,但有人可以解释为什么它是 8、Lbound 和 UBound,我的考试中出现了这种类型的问题,我在解决这个问题时遇到了一些问题。
非常感谢
【问题讨论】:
-
一个关于
vb.net ubound的简短谷歌在第二个链接上给了我(这可能因您的计算机而异)UBound 函数的微软文档。 -
Console.WriteLine(arr(LBound(arr) + 5) + arr(UBound(arr) - 2))将等于 8,因为lbound(arr) = 0 + 5 and ubound(arr)= 5 - 2 = 3。 lbound 得到数组中最左边的数字,所以在你的情况下为 0,你添加了 5,Ubound 得到最高的 bascailly 所以为 5 - 2,最后将结果相加 = 5 + 3 = 8! -
在
arr(LBound(arr)) => arr(0)中输入0 => (1 -1)然后添加5 => (0 + 5)。在arr(UBound(arr)) => arr(5)中输入5 => (6 - 1)。然后,减去2 => (5 - 2)。所以你有(0 + 5) + (5 - 2)。
标签: arrays vb.net bounds computation reflex