Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

How to create and set values to a 3d array in VB.NET

1 Answer

0 votes
Imports System

Class Program
    Public Shared Sub InitializeArray(ByVal array As Integer(,,), ByVal x As Integer, ByVal y As Integer, ByVal z As Integer)
        For i As Integer = 0 To x - 1
            For j As Integer = 0 To y - 1
                For k As Integer = 0 To z - 1
                    array(i, j, k) = i + j + k
                Next
            Next
        Next
    End Sub

    Public Shared Sub PrintArray(ByVal array As Integer(,,), ByVal x As Integer, ByVal y As Integer, ByVal z As Integer)
        For i As Integer = 0 To x - 1
            For j As Integer = 0 To y - 1
                For k As Integer = 0 To z - 1
                    Console.Write(array(i, j, k) & " ")
                Next

                Console.WriteLine()
            Next
        Next
    End Sub

	Public Shared Sub Main()
        Dim x As Integer = 2, y As Integer = 3, z As Integer = 4
        Dim array As Integer(,,) = New Integer(x - 1, y - 1, z - 1) {}

        InitializeArray(array, x, y, z)
        PrintArray(array, x, y, z)
    End Sub
End Class


' run:
'
' 0 1 2 3 
' 1 2 3 4 
' 2 3 4 5 
' 1 2 3 4 
' 2 3 4 5 
' 3 4 5 6 
'

 



answered Apr 21, 2025 by avibootz
...