Asked By
howel dinh
30 points
N/A
Posted on - 04/14/2012
I need to know how making an array of array is done in C#. Below is my code:
I don't think I've done it right but can you check it please? Also how can I pass an array to a function?
Making an Array of Arrays and Pass it
Â
Hi Howel,
First you need to create single dimensional array:
Â
TextBox[] tbArray0 = new TextBox[] {tb1,tb2,tb3,…};
//..
TextBox[] tbArray15 = new TextBox[] {tb1,tb2,tb3,…};
To declare an array of arrays  in C#, it requires syntax such as the following. It's assumed that tbArray0 to tbArray15 are single dimensional arrays of length 16 though they can be of any length:
Â
TextBox[][] tbArrays = new TextBox[16][];
tbArrays[0] = tbArray0;
tbArrays[1] = tbArray1;
//..
tbArrays[15] = tbArray15;
Â
To pass such an array to a function requires a declaration such as:
Â
void SomeFunc(TextBox[][] tbArrays)
Â
The first element of the first array can then be accessed with the expression tbArray[0][0] and the last element of the last array with tbArray[15][15].
Â
I hope it helped.
Â