|
|
Title | Declare jagged arrays in VB .NET |
Keywords | variable, VB .NET, initialization, declaration, array, jagged array |
Categories | VB.NET |
|
|
A jagged array is really an array of arrays. Each entry in the array is another array
that can hold any number of items. Because each entry can hold any number of other items,
the array has a jagged appearance.
Declare a jagged array by using multiple sets of parentheses.
|
|
' 10 entries, each of which
' is an array of Integers.
Dim values(9)() As Integer
|
|
You can initialize a jagged array when you declare it, but it isn't quite as easy as
it is to initialize other types of arrays. Remember that the first-level objects are
arrays, not a simpler data type. You need to create a new array object for each
first-level entry.
You can do this using separate variables as in the following code.
|
|
Dim values1() As Integer = {1, 2, 3}
Dim values2() As Integer = {4, 5}
Dim all_values()() As Integer = {values1, values2}
|
|
Alternatively you can initialize the sub-arrays in the jagged array's definition using the New
keyword.
|
|
Dim all_values()() As Integer = { _
New Integer() {1, 2, 3}, _
New Integer() {4, 5} _
}
|
|
Related topics:
|
|
-->
|
|