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.

5
  • Use List of List i.e List<List<>>. Commented Oct 27, 2015 at 6:49
  • Create a class which has a List<Whatever>. Then use List<YourClass>. That way your code will make sense. Otherwise, nobody know what your List<List<double>> holds.. Commented Oct 27, 2015 at 6:54
  • 1
    Please do look into the following question: stackoverflow.com/questions/1603170/… Commented Oct 27, 2015 at 7:11
  • @Schuere thanks, that's what I was looking for - it's not difficult, just finding the right information. I'm still stuck in c++ headspace. Commented Oct 28, 2015 at 20:12
  • @Chaz, glad to be of help Commented Oct 29, 2015 at 8:20

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.