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,907 questions

51,839 answers

573 users

How to clone a two-dimensional array in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Public Shared Sub Print(ByVal arr2D As Integer(,))
        Dim rows As Integer = arr2D.GetLength(0)
        Dim cols As Integer = arr2D.GetLength(1)

        For i As Integer = 0 To rows - 1
            For j As Integer = 0 To cols - 1
                Console.Write("{0, 4}", arr2D(i, j))
            Next

            Console.WriteLine()
        Next
    End Sub

    Public Shared Sub Main(ByVal args As String())
        Dim grid As Integer(,) = {
        	{1, 2, 3, 4},
        	{5, 6, 7, 8},
        	{9, 10, 11, 12}}

        Console.WriteLine("Original Array")
        Print(grid)

        Dim arr2D As Integer(,)
        arr2D = CType(grid.Clone(), Integer(,))
        Console.WriteLine("Cloned Array")
        Print(arr2D)
    End Sub
End Class



' run:
'
' Original Array
'   1   2   3   4
'   5   6   7   8
'   9  10  11  12
' Cloned Array
'   1   2   3   4
'   5   6   7   8
'   9  10  11  12
'  

 



answered Mar 7, 2025 by avibootz
...