In this article You will learn how to use
Arrays in VB.NET.
ARRAY
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.
Dimentions
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.
-
Rectangular Array
-
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.
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())
Next
Console.WriteLine(" sorted array
is:")
Array.Sort(num)
For Each n As Integer In
num
Console.WriteLine(n)
Next
End Sub
End Module
OUTPUT: