Making an Array of Arrays and Pass it

Asked By 30 points N/A Posted on -
qa-featured

I need to know how making an array of array is done in C#. Below is my code:

TextBox[][] tbArrays = new TextBox[16][];
tbArrays[0] = tbArray0;
tbArrays[1] = tbArray1;
//..
tbArrays[15] = tbArray15;

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?

SHARE
Answered By 0 points N/A #110581

Making an Array of Arrays and Pass it

qa-featured

 

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.

 

Login/Register to Answer

Related Questions