Definition
An array is a collection of similar type of data element or data type. Elements of an array occupies contagious location and have equally spaced addresses in the memory. Arrays in .NET enabled languages are inherited from the System.Array class. Arrays can be declared using Dim, ReDim, Static, Private, Public and Protected keywords. In VB.NET Array don't have fix sized.
Syntax/Declaration:-
Dim
arrayname(size or No. of elements) As type 'Declare
and initialize array of size n
OR
Dim
arrayname() As type =
New type(size){}
OR
Dim
arrayname() As type
arrayname=New type(size){}
Example:-
Dim
num(5) As Integer
'Declaration & Initialization of an
array of integers of size 5
Dim
num() As Integer
'Another way to declare and initialize arrays
num = New Integer() {0,1,2,3,4}
OR
num = New Integer(5){}
Accessing Elements of Array:-
We can access elements of an array by their
numerical index value. Index of the first element of array always starts with
zero(0). You must specify the number of array elements by indicating the upper
bound of the array. The upper bound is the number that specifies the index of
the last element in the array.
Example:-
Imports System.Console
Module Module1
Sub main()
Dim num(5) As Integer 'Declare and initialize array of size 5
num(0) = 1 'First
element of the array always start with index 0
num(1) = 2
num(2) = 3
num(3) = 4
num(4) = 5
WriteLine("Element of the array at
the fourth location is :- " & " "
& num(3))
Read()
End Sub
End Module
Output:-

Types of Array :
Arrays are of two types: - Single
Dimensional Array and Multidimensional Array. Dimension of an array refers to
the direction in which we can vary with the specification of the array's
element. We can determine the dimensions of an array by the number of subscripts
that are used to identify the position of any array element. We must declare
the dimension of the array before using them into our program.
A single dimensional array is identified by only a single subscript and a
two-dimensional array is identified by two subscripts. The declaration of an
array comprises the name of the array and the number of elements the array can
contain.
For example:-
Syntax to declare a single dimensional array is:-
Dim
arrayname(size or no of elements) As type
Example:
Dim
OneDimensionalArr(5) As
Integer 'Declaration
of a single dimensional array of integer type
and syntax to declare a multidimensional array is :-
Dim
arrayname ( no. of 1st element, no. of 2nd element,.......) As type
Example:
Dim
TwoDimensionalArr(1,2) As
Integer
'Declaration of two
dimensional array having two rows and three columns
Note: An
array can have more than two dimension. An array can have up to 32 dimensions
although more than three dimensions are unusual and difficult to handle and
visualize. Adding a new dimension in the array will increase the storage space
significantly, thus always use multidimensional arrays carefully.


Shekhar ChauhanPosted Nov 8, 2012, 10:31 PM
Nice info, thanks for sharing.