MAKING AN ARRAY OF ARRAYS

Andrew Watson

Total Post:39

Points:273
Posted by  Andrew Watson
C# 
C#
 1270  View(s)
Ratings:
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.
  1. Uttam Misra

    Post:125

    Points:897
    Re: Making an array of arrays

    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].

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!