Declaring - Fixed Size
Numbers can be grouped together into arrays to represent both matrices and vectors
These can be represented by using an Array data structure.
A single-dimensional array of objects is declared like this:
type[] arrayName;
int[] array = new int[5];
int[] array1 = new int[] { 1, 3, 5, 7, 9 };
int[] array2 = {1, 3, 5, 7, 9};
string[] days = {"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat"};
The default value of numeric array elements is zero
The default value of any reference elements is null
Fixed Size Arrays
In C# the number inside the bracket represents the number of items in the array
int[] myArray1 = new int[3] { 1, 2, 3 };
int[] myArray2 = new int[] { 1, 2, 3 };
int[] myArray3 = { 1, 2, 3 };
var myArray4 = new[] {1, 2, 3}; // implicitly typed, inferred from items
System.Array myArray5 = System.Array.CreateInstance(typeof(System.Int32), 3);
When isize = 5, there are 5 elements, myArray(0) to myArray(4).
long[] myArray = new long[5];
int isize = 5;
long[] myArray = new long[isize];
long[] myArray = new long[3];
myArray[0] = 5;
myArray[1] = 10;
myArray.SetValue(15,2);
Not Zero Based
//1 dimensional - zero based
System.Array i2 = Array.CreateInstance(typeof(int), new int[] { 2 }, new int[] { 100 });
//1 dimensional - non zero based
System.Array myArray = Array.CreateInstance(typeof(double), new int[1] { 12 }, new int[1] { 1 });
Declaration and creation can be done in 2 steps or combined into 1 line
Values can be intialised or left as the defaults
VB.Net Syntax
Option Base 1
This is not possible in VB.Net.
In .NET all arrays start at zero. In VBA you can use the Option Base 1 to start your arrays from 1 instead.
You will have to make all your indexes zero based
To get the total number of elements use ArrayName.Length
Replace LBound and UBound with GetUpperBound(0) and GetLength(0) - 1
In .NET an array variable is a Reference type
Declaring
In VB.Net the number inside the bracket represents the index number of the last element.
When isize = 5, there are 6 elements, myArray(0) to myArray(5)
Dim myArray(5) As Long
Dim isize As Integer = 5
Dim myArray(isize) As Long
You cannot specify a dimension on the array type in VB.Net.
In VB.Net you can use curly brackets and these can come after the type or after the variable
This is very confusing because if you are declaring a fixed-size array then you must put the curly brackets after the variable.
Dim myArray() As Long
Dim myArray As Long()
In VB.Net it is good practice to include "New" when declaring and initialising an array on one line.
You can only use "New" when initiating with curly brackets.
Dim myArray() As String = New String() {"one","two","three"}
Dim myArray() As String = {"one","two","three"}
Dim myArray(2) As String = {"one","two","three"} ??
The following 2 lines are identical in VB.NET
Dim myarray() As String
Dim myarray As String()
The following lines are all allowed
Dim myarray(6) As Integer
Dim myarray() As Integer = New Integer() {}
Dim myarray() As Integer = {1,2,3,4,5}
Dim myarray() As Integer = New Integer() {1,2,3,4,5}
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext