One dimensional Arrays in Visual Basic

Arrays allow you to store a series of values that have the same data type. All arrays start at a fixed lower bound of 0. When you create an array in VB, you simply specify the upper bound.

Example

Module Module1

    Sub Main()

        ' Create an array with two strings (from index 0 to index 3)
        Dim StringArray(3) As String
        StringArray(0) = "element1"
        StringArray(1) = "element2"
        StringArray(2) = "element3"
        StringArray(3) = "element4"

        Console.WriteLine(StringArray(0))
        Console.WriteLine(StringArray(1))
        Console.WriteLine(StringArray(2))
        Console.WriteLine(StringArray(3))

        Console.ReadLine()

    End Sub

End Module

We can also initialize array elements while declaring arrays as :

Example

Module Module1

    Sub Main()

        ' Create an array with two strings (from index 0 to index 2)
        Dim StringArray() As Integer = {1, 2, 3}

        Console.WriteLine(StringArray(0))
        Console.WriteLine(StringArray(1))
        Console.WriteLine(StringArray(2))

        Console.ReadLine()

    End Sub

End Module
Share

You may also like...