0

Back in the day I used to study C++... we used to do arrays of arrays at school, now called jagged arrays I see in C#.

However, I need to use a List<> whereby I can just add another array to it.

In C#, which is the best way to achieve a similar logic, such that each individual 'cell' of a List<> actually contains a whole array? All the examples I have found, simply render the content of an array linearly into a List, cell for cell, which is not what I want.

Any help appreciated.

Chaz
  • 2,311
  • 1
  • 12
  • 9

1 Answers1

1

A List is generic, meaning it can be a list of any type. So, to have an array in each individual cell you could define a List like this:

public List<int[]> myArrayList;

Or you could even have a List of Lists:

public List<List<T>> myListOfLists;

Keep in mind that you will have to initialise both the outer List and the inner array/list in order to use them.

kkyr
  • 3,785
  • 3
  • 29
  • 59