VB.NET Arrays

Two-Dimensional Array

Another frequently used array is two-dimensional array. A two-dimensional array stores values in rows and columns. The row index starts from 0. The column index also starts from 0. You will use the New keyword to allocate a two-dimensional array.



Index 


0


1


2


0

1

2

3


1

4

5

6

Example:


Module Module1
 
    Sub Main()
       'Declaring and allocating the 2D-array of 2 rows and 3 columns
        Dim arr(,) As Integer
        arr = New Integer(1, 2) {{1, 2, 3}, {4, 5, 6}}
        For i = 0 To arr.GetUpperBound(0) 'max row index
            For j = 0 To arr.GetUpperBound(1) 'max column index
                Console.Write(arr(i, j) & vbTab)
            Next
            Console.WriteLine()' print new line
        Next
        Console.ReadLine()
 
    End Sub
End Module


HTML Comment Box is loading comments...



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.