2D Fixed AND Variable-Length Array

I need a 2D array that is a fixed length in one dimension and variable length in the other. In other words, I need a fixed-length array with 8 elements, each of which is a variable-length array. These variable arrays start out empty, so their lengths would initially be zero. I’m translating some old Director/Lingo code, and it’s trivial to do it there.

I normally use lists when I need variable length, but you can’t create an empty, fixed-size list. Can you? If so, I can’t figure out how. Or maybe a JS array of lists? None of those things seem to work.

The only solution I can see right now is to use 8 separate lists, but there are several of these and that would really complicate things (like no more loops). Any suggestions?

var myArray = new List.<int>[8];
for (var i = 0; i < myArray.Length; i++) {
    myArray[i] = new List.<int>();
}
myArray[0].Add (42);
Debug.Log (myArray[0][0]);

You would never use a JS array for anything, ever. :wink:

–Eric

Thanks. I already tried something like this, but I don’t think I initialized the array correctly.