Tutorial by Examples

Dim array(9) As Integer ' Defines an array variable with 10 Integer elements (0-9). Dim array = New Integer(10) {} ' Defines an array variable with 11 Integer elements (0-10) 'using New. Dim array As Integer() = {1, 2, 3, 4} ' Defines an Integer array variable a...
Dim array = New Integer() {1, 2, 3, 4} or Dim array As Int32() = {1, 2, 3, 4}
Dim array() As Integer = {2, 0, 1, 6} ''Initialize an array of four Integers. Dim strings() As String = {"this", "is", "an", "array"} ''Initialize an array of four Strings. Dim floats() As Single = {56.2, 55.633, 1.2, 5.7743, 22.345} ...
Dim array2D(,) As Integer = {{1, 2, 3}, {4, 5, 6}} ' array2D(0, 0) is 1 ; array2D(0, 1) is 2 ; array2D(1, 0) is 4 Dim array3D(,,) As Integer = {{{1, 2, 3}, {4, 5, 6}}, {{7, 8, 9}, {10, 11, 12}}} ' array3D(0, 0, 0) is 1 ; array3D(0, 0, 1) is 2 ' array3D(0, 1, 0) is 4 ; array3D(1, 0, 0) is 7 ...
Note the parenthesis to distinguish between a jagged array and a multidimensional array SubArrays can be of different length Dim jaggedArray()() As Integer = { ({1, 2, 3}), ({4, 5, 6}), ({7}) } ' jaggedArray(0) is {1, 2, 3} and so jaggedArray(0)(0) is 1 ' jaggedArray(1) is {4, 5, 6} and so jagge...
Since arrays are reference types, an array variable can be null. To declare a null array variable, you must declare it without a size: Dim array() As Integer Or Dim array As Integer() To check if an array is null, test to see if it Is Nothing: Dim array() As Integer If array Is Nothing Th...
Since arrays are reference types, it is possible to have multiple variables pointing to the same array object. Dim array1() As Integer = {1, 2, 3} Dim array2() As Integer = array1 array1(0) = 4 Console.WriteLine(String.Join(", ", array2)) ' Writes "4, 2, 3"
With Option Strict On, although the .NET Framework allows the creation of single dimension arrays with non-zero lower bounds they are not "vectors" and so not compatible with VB.NET typed arrays. This means they can only be seen as Array and so cannot use normal array (index) references. ...

Page 1 of 1