Jagged Array in VB.NET

How to use Jagged Array in VB.NET?

Explanation

Jagged Array

Jagged Array is also an Multi Dimensional array with different number of rows and column elements. This type of array can be used to reduce the space occupied by an array, since all rows don't have equal number of columns.
Example:

Module Module1
Sub Main()
Dim one() As Integer = {1, 2, 3}
Dim two() As Integer = {3, 4, 5, 6, 7}
Dim jag()() As Integer = {one, two}
Dim i, j As Integer
For i = 0 To jag.Length - 1
For j = 0 To jag(i).Length - 1
Console.Write((jag(i)(j)))
Next
Console.WriteLine()
Next
Console.ReadLine()
End Sub
End Module
Result:

123
34567
Description:

In the above example jag is a jagged array that has different number of rows and columns elemenst referenced using two other arrays one and two.

Visual Basic Tutorial


Ask Questions

Ask Question