I would like to create a list inside another list. How can I do this?
And how do I retrieve values from the list which is inside another list?
I would like to create a list inside another list. How can I do this?
And how do I retrieve values from the list which is inside another list?
I'm not sure if I correctly understand your question. Do you want something like this?
var listOfList = new List<List<int>>();
listOfList.Add(new List<int>());
listOfList[0].Add(42);
Something like this, you mean:
List<List<int>> someList = new List<List<int>>();
This is a List of Lists
If you want strong type lists of for example ints:
var list = new List<List<int>>();
of for none strong type lists:
new List<List<object>>();
pfuh ... correct answers already thrown in ... just another style:
var mySpecialList = new List<List<int>>
{
new List<int>
{
4
},
new List<int>
{
12,
17
}
}
You could always create a custom class to contain your data e.g.
public class myContainer<T>
{
public List<T> contents {get; set;}
}
List<myContainer> x = new List<myContainer>();
This has the benefit that if the data type in myContainer changes its isolated from code to get the sub-lists.