Tangible Software Solutions

The Most Trusted Name in Source Code Conversion

Arrays in C#, VB, C++, and Java

All programming languages have syntax which allows creating variables which refer to a set of identically-typed values.


int[] myArray = new int[3];
int[,] myTwoDimensionArray = new int[2, 3];
int[][] myJaggedArray = new int[3][];


'short' syntax:
Dim myArray(2) As Integer
Dim myTwoDimensionArray(1, 2) As Integer
Dim myJaggedArray(2)() As Integer

'long' syntax:
Dim myArray() As Integer = New Integer(2){}
Dim myTwoDimensionArray(,) As Integer = New Integer(1, 2){}
Dim myJaggedArray()() As Integer = New Integer(2)(){}

Note: Unlike other programming languages, arrays are declared specifying their upper bound in VB, not their length.

Note: VB also allows placing the array specifier after the variable type (e.g., Dim myArray As Integer() = New Integer(2){}), but only in the 'long' syntax.

Native C++:

int *myArray = new int[3];
int **myTwoDimensionArray = new int*[2][3];
int **myJaggedArray = new int*[3];

However, C++ developers are increasingly using std::vector in place of arrays, so the first array would often be rewritten as a vector:
std::vector myArray(3);


array<int> ^myArray = gcnew array<int>(3);
array<int, 2> ^myTwoDimensionArray = gcnew array<int, 2>(2, 3);
array<array<int>^> ^myJaggedArray = gcnew array<array<int>^>(3);


int[] myArray = new int[3];
int[][] myTwoDimensionArray = new int[2][3];
int[][] myJaggedArray = new int[3][];

Note: Java also allows placing the array specifier after the variable name (e.g., int myArray[]).

Copyright © 1997 - 2017 Tangible Software Solutions Inc.