Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the 3D array
By Nidhi Last Updated : November 11, 2024
Three-Dimensional (3D) Array in VB.Net
Here, we will create a three-dimensional array and then print all elements on the console screen.
Program/Source Code:
The source code to demonstrate the 3D array is given below. The given program is compiled and executed successfully.
VB.Net code to create a three-Dimensional (3D) Array
'VB.Net program to demonstrate the 3D array.
Module Module1
Sub Main()
' Three Dimensional Array
Dim ThreeDArray As Integer(,,) = New Integer(1, 1, 2) {{{1, 2, 3}, {4, 5, 6}}, {{7, 8, 9}, {10, 11, 12}}}
Console.WriteLine("3D Array Elements")
Console.WriteLine("=================")
For i As Integer = 0 To 1
For j As Integer = 0 To 1
For k As Integer = 0 To 2
Console.WriteLine("ThreeDArray[{0},{1},{2}] = {3}", i, j, k, ThreeDArray(i, j, k))
Next
Next
Next
End Sub
End Module
Output
3D Array Elements
=================
ThreeDArray[0,0,0] = 1
ThreeDArray[0,0,1] = 2
ThreeDArray[0,0,2] = 3
ThreeDArray[0,1,0] = 4
ThreeDArray[0,1,1] = 5
ThreeDArray[0,1,2] = 6
ThreeDArray[1,0,0] = 7
ThreeDArray[1,0,1] = 8
ThreeDArray[1,0,2] = 9
ThreeDArray[1,1,0] = 10
ThreeDArray[1,1,1] = 11
ThreeDArray[1,1,2] = 12
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 three-dimensional array ThreeDArray. Here, we initialized the array elements and then print all elements on the console screen.
VB.Net Array Programs »