Visual Basic .NET数组定义
示例
Dim array(9) As Integer ' Defines an array variable with 10 Integer elements (0-9).
Dim array = New Integer(10) {} ' Defines an array variable with 11 Integer elements (0-10)
'using New.
Dim array As Integer() = {1, 2, 3, 4} ' Defines an Integer array variable and populate it
'using an array literal. Populates the array with
'4 elements.
ReDim Preserve array(10) ' Redefines the size of an existing array variable preserving any
'existing values in the array. The array will now have 11 Integer
'elements (0-10).
ReDim array(10) ' Redefines the size of an existing array variable discarding any
'existing values in the array. The array will now have 11 Integer
'elements (0-10).从零开始
中的所有数组VB.NET都是从零开始的。换句话说,VB.NET数组中第一项的索引(下限)始终为0。默认情况下,较旧的VB版本(例如VB6和VBA)是基于一个的,但是它们提供了一种覆盖默认范围的方法。在早期版本的VB中,可以明确说明下限和上限(例如Dimarray(5To10),在VB.NET中,为了保持与其他.NET语言的兼容性,已删除了灵活性,并且0始终强制执行下限。),To仍然可以在VB.NET中使用该语法,这可以使范围更加明确,例如,以下示例均与上面列出的示例等效:
Dim array(0 To 9) As Integer
Dim array = New Integer(0 To 10) {}
ReDim Preserve array(0 To 10)
ReDim array(0 To 10)嵌套数组声明
Dim myArray = {{1, 2}, {3, 4}}
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西