Multi-dimension arrays

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I tried making a 3x3 array like

static int[, ,] Table = {{1,2,3},{4,5,6},{7,8,9}};

The example from the docs is for a two dimensioned array and it works fine.

Are dimensions greater than 2 disallowed?
 
Your syntax isn't right. Try this:

static int[][] Table = new int[][] { new int[] { 1,2,3 }, new int[] {
4,5,6 }, new int[] { 7,8,9 }};

There is no limit to the number of dimensions, or the size of each
dimension.
 
static int[, ,] Table = {{1,2,3},{4,5,6},{7,8,9}};

You have too many commas: 2 commas gives a 3D array.

This gives a 2D array 3 rows by 3 columns:

static int[,] Table = {{1,2,3},{4,5,6},{7,8,9}};
 
Hi Harry,

As MarkT mentioned your declaration is for a 2D array.
To make it 3D add another set ontop of what you have:

static int[,,] Table = { {{1,2,3},{4,5,6},{7,8,9}} ,
{{1,2,3},{4,5,6},{7,8,9}} };
 
Back
Top