vb.net Visual Basic 数组的第一个元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19347933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual basic first element of array
提问by DanMc
I'm just starting with visual basic.
我只是从视觉基础开始。
The first element in an array
数组中的第一个元素
i.e. dim y(9)as Integer
即dim y(9)作为整数
Will that have elements 0-8or 1-9in?
将有元素0-8或1-9在?
i.e. if I did
即如果我做了
y(1) = 84
does that make the first or second element in the array equal to 84?
这是否使数组中的第一个或第二个元素等于 84?
I've looked at a few online sources and I'm a bit confuzzled.
我查看了一些在线资源,我有点困惑。
Thanks
谢谢
采纳答案by varocarbas
The first position for arrays in VB.NET is zero; same rules apply to any in-built collection/function requiring indexing and to other .NET languages, like C#. On the other hand, "old" VB (VB6 and older or VBA) has zero as first index for arrays and one for in-built functions (this is somehow confusing for people coming from VB to VB.NET). What is common to all the VB versions (.NET and older ones) and different to other languages like C#, is that the number used when instantiating the array (9 in y(9)) does not indicate its size but its last index (the size of y(9)is 10).
VB.NET 中数组的第一个位置为零;相同的规则适用于任何需要索引的内置集合/函数以及其他 .NET 语言,如 C#。另一方面,“旧”VB(VB6 和更早版本或 VBA)的第一个索引是零,作为数组的第一个索引和一个用于内置函数的索引(这对于从 VB 到 VB.NET 的人来说有点混乱)。所有 VB 版本(.NET 和旧版本)的共同点以及与 C# 等其他语言不同的是,实例化数组时使用的数字(9 in y(9))不表示其大小,而是表示其最后一个索引(的大小y(9)是10)。
In summary, your array includes 10 positions: from 0 to 9.
总之,您的数组包括 10 个位置:从 0 到 9。
回答by Rahul Tripathi
The elements in the array start from 0 in VB.NET
数组中的元素在VB.NET中从0开始
A sample example from MSDN:
来自MSDN的示例示例:


You may also find this interesting to read:- Why numbering should start at zero
您可能还会发现这很有趣:-为什么编号应该从零开始

