简体   繁体   中英

Visual basic first element of array

I'm just starting with visual basic.

The first element in an array

ie dim y(9) as Integer

Will that have elements 0-8 or 1-9 in?

ie if I did

y(1) = 84

does that make the first or second element in the array equal to 84?

I've looked at a few online sources and I'm a bit confuzzled.

Thanks

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).

In summary, your array includes 10 positions: from 0 to 9.

The elements in the array start from 0 in VB.NET

A sample example from MSDN :

在此处输入图片说明

You may also find this interesting to read:- Why numbering should start at zero

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM