Explain two Dimensional Array with an example

In this article I share my knowledge about Two dimensional array
  • 3298

First we should now what is Array

Array is a construct which store data and we can access that data by using numeric index or subscript and by using array you can reduce you code length your application become shorter. There is a Array class in the system namespace arrays in Visual Basic .Net inherit from this class. All the arrays in VB are zero based mean the index of the first element is zero and they are numbered sequentially, you have to given a last index for the array to specifying its limit.

You can declare array by using Dim, ReDim, Static, Private, Public and Protected keywords. Arrays can be two types, one dimensional or more than one dimensional array, dimension stands for the number of subscripts used to identify an individual element, in Visual basic you can specify up to 32 dimensions.

In this article we discuss about two dimensional array, first you go through the below code than we discuss more:-


    Module module1
        Sub Main()
            Dim str_values(,,) As String = _
            { _
                { _
                    {"123", "456", "789"}, _
                    {"111", "222", "333"} _
                }, _
                { _
                    {"000", "001", "002"}, _
                    {"100", "200", "300"} _
                } _
            For a As Integer = 0 To 1
                For b As Integer = 0 To 1
                    For c As Integer = 0 To 2
                        Console.Write(str_values(a, b, c) & " ")
                    Next c
                Next b
            Next a
        End Sub

Two Dimensional arrays are arrays in which each member of each dimension is extended in each other dimension by the same length. We declare a two Dimensional array by specifying additional dimensions at declaration. I hope the above example code demonstrate clear you the declaration of a multidimensional array.



More Articles

© 2020 DotNetHeaven. All rights reserved.