Size of array in Visual Basic?

前端 未结 5 965
一向
一向 2020-12-09 09:10

I\'ve tried this code in VB:

Dim a(1) As Byte
Console.WriteLine(a.Length)

The output is \"2\". Anyone any idea why?

5条回答
  •  眼角桃花
    2020-12-09 09:22

    The previous answers each have pieces of the correct answer, but not the full correct answer. When you declare an array (Like with your code: Dim a(1) As Byte) the number you put in the array declaration (in this case, 1) is NOT a declaration of how many entries in the array, it is a declaration of the upper boundary of the array.

    So, in your declaration, you're creating an array with 2 entries: a(0) and a(1)

提交回复
热议问题