Multi dimensional String Array

In programming, an array provides a convenient way to store and manage related values under a single name. It allows accessing individual values, known as elements, by using an index or subscript. The index serves as a numerical identifier that differentiates between elements within the array.

Multidimensional arrays

Arrays can also have multiple dimensions, referred to as multidimensional arrays. Each dimension represents a specific direction or axis in which the elements of the array can vary. For instance, a two-dimensional array employs two indexes to access its elements effectively.

Dim values() As Double

To illustrate, consider the following example that declares a variable to store a two-dimensional array of office counts. This array is designed to track office counts for buildings ranging from 0 to 40 and floors ranging from 0 to 5. The specific syntax and declaration may vary depending on the programming language used.

Using a two-dimensional array in this manner, developers can organize and access office counts based on building and floor numbers. This allows for efficient storage and retrieval of data related to different locations within a complex or multi-level structure.

Dim offices(40, 5) As Byte

The following VB.NET program shows a simple example of how to insert values in a two dimensional array and retrieve the values from two dimensional array.

Full Source VB.NET
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i, j As Integer Dim strArr(1, 2) As String strArr(0, 0) = "First (0,0)" strArr(0, 1) = "Second (0,1)" strArr(1, 0) = "Third (1,0)" strArr(1, 1) = "Fourth (1,1)" For i = 0 To strArr.GetUpperBound(0) For j = 0 To strArr.GetUpperBound(0) MsgBox(strArr(i, j)) Next Next End Sub End Class

Conclusion

Using multidimensional arrays is particularly useful when dealing with data that has multiple dimensions or when there is a need to represent complex relationships between elements. It provides a structured and organized approach to managing and manipulating related data within a program.