An array stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.
All arrays consist of contiguous memory locations. The lowest address corresponds to the first element, and the highest address to the last element.
Creating Arrays in VB.Net
To declare an array in VB.Net, you use the Dim statement. You can also initialize the array elements while declaring the array. The elements in an array can be stored and accessed by using the index of the array.
Dynamic Arrays
Dynamic arrays are arrays that can be dimensioned and re-dimensioned as the program requires. The ReDim statement can be used to declare a dynamic array.
The syntax for ReDim statement −
ReDim [Preserve] arrayname(subscripts)
Where,
- The Preserve keyword aids in the preservation of data in an existing array when it is resized.
- arrayname is the name of the array that will be re-dimensioned.
Multi-Dimensional Arrays
Multidimensional arrays are supported by VB.Net. Rectangular arrays are another name for multidimensional arrays.
Jagged Array
A Jagged array is a collection of arrays. The code below explains how to declare a jagged array called scores of Integers.
Dim scores As Integer()() = New Integer(5)(){}
The Array Class
The Array class is the foundation for all arrays in VB.Net. It is specified in the namespace System. The Array class contains several attributes and methods for working with arrays.
Please see Microsoft documentation for a complete list of Array class properties and methods.