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.
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].
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
http://www.mindstick.com/Articles/1b8bb376-f49f-4be4-9abf-7aeccf44f809/?Array%20in%20C%20NET
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].