Home > DeveloperSection > Forums > Making an array of arrays
Andrew Watson
Andrew Watson

Total Post:39

Posted on    March-05-2011 2:43 AM

 C# C# 

 2 Reply(s)
 1061  View(s)
Rate this:
I need to implement an array of arrays which are Textbox so that I can reuse some of the code by being able to pass this array of arrays.

I have functions that take a Textbox as a parameter.

Uttam Misra

Total Post:125

Posted on    March-05-2011 2:53 AM

To declare an array of arrays (as opposed to a 2D array) in C# 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].

John Smith

Total Post:102

Posted on    March-05-2011 2:55 AM

Modified On Mar-05-2011 02:57:14 AM

Don't want to miss updates? Please click the below button!

Follow MindStick