×

VB.Net Programs

VB.Net program to demonstrate the jagged array

By Nidhi Last Updated : November 11, 2024

Jagged Array in VB.Net

Here, we will create a jagged array, a jagged array contains a different number of elements in each row.

Program/Source Code:

The source code to demonstrate the jagged array is given below. The given program is compiled and executed successfully.

VB.Net code to demonstrate the example of jagged array

'VB.Net program to demonstrate the jagged array.

Module Module1

    Sub Main()
        Dim jaggedArray As Integer()() = New Integer(2)() {}

        jaggedArray(0) = New Integer(4) {1, 2, 3, 4, 5}
        jaggedArray(1) = New Integer(2) {1, 2, 3}
        jaggedArray(2) = New Integer(5) {1, 2, 3, 4, 5, 6}

        Console.WriteLine("Jagged Array: ")
        For i = 0 To jaggedArray.Length - 1 Step 1
            For j = 0 To jaggedArray(i).Length - 1 Step 1
                Console.Write("{0} ", jaggedArray(i)(j))
            Next
            Console.WriteLine()
        Next
    End Sub
    
End Module

Output

Jagged Array:
1 2 3 4 5
1 2 3
1 2 3 4 5 6
Press any key to continue . . .

Explanation

In the above program, we created a module Module1 that contains a function Main(). In the Main(), we created a jagged array jaggedArray that contains the different number of elements in each row. After that, we printed the jagged array on the console screen.

VB.Net Array Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.