Arrays in VB.NET

In this article we will learn how to use Arrays in VB.NET.
  • 6875

In this article You will learn how to use Arrays in VB.NET.


Array is the collection of similar type of element. Arrays are declared using Dim, ReDim, Static, Private, Public and Protected keywords. In VB.NET Array have not fix sized or An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier.


The dimensionality of an array refers to the number of subscripts used to identifyan individual element.

Types of Array: There are following types of an array in VB.NET.

Single Dimensional Array:  Define the single Dimensional array as following:

Dim num As Integer() = New Integer(4) {}
num(0) = 67
num(1) = 55
Multi-Dimensional array:  Such can be of two types.
  1.   Rectangular Array
  2. Jagged Array or Complex Array

Rectangular Array:- Having equal number of elements in each row. Rectangular arrays are arrays in which each member of each dimension is extended in each other dimension by the same length.


Rectangle array is define as following:

Dim num As Integer(,) = New Integer(1, 2) {}

num(0, 0) = 89

Jagged Array : Jagged Array is an array of arrays in whichthe length of each array can differ.

  • Array within array is knows as Jagged Array

  • Can have un-equal number of elements in each row

Define such as following:


Dim num As Integer()() = New num(2)() {}
num(0) = New Integer(4) {}
num(1) = New Integer(6) {}
num(2) = New Integer(8) {}


For example :


Module Module1

   Sub Main(ByVal args As String())

        Dim num As Integer() = New Integer(8) {}

        Console.WriteLine("Enter {0} number : ", num.Length)

        For i As Integer = 0 To num.Length - 1

            num(i) = Integer.Parse(Console.ReadLine())


        Console.WriteLine(" sorted array is:")


        For Each n As Integer In num



End Sub

 End Module





More Articles

© 2020 DotNetHeaven. All rights reserved.