Click here to Skip to main content
15,212,528 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi all, i have a question regarding List<t>. I was wondering can you actually have a list of lists...for example a List<list><string[]>>...i am trying to do this now but i keep on getting string arrays instead of the list of arrays. Any help will be much appreciated...thanking you in advance.
Posted
Comments
[no name] 17-Jul-13 10:13am
   
You are creating a list of string arrays and you are surprised that you are getting a list of string arrays? And yes you can have lists contain lists.... list<list<string>>
Rate this:
Please Sign up or sign in to vote.

Solution 2

What Pheonyx means is probably

List<List<string>> listOfList;


However, note that this list contains reference types again, so you have to instantiate every element on its own. For instance:

var listOfList = new List<List<string>>();

//Lets add a list of strings to the list of list of strings
listOfList.Add(new List<string>());
//Lets add a string to the list of strings
listOfList[0].Add("Some string");

//Another round
listOfList.Add(new List<string>());
listOfList[1].Add("Another string");
listOfList[1].Add("Final string!");

//listOfList[0][0] == "Some string"
//listOfList[1][0] == "Another string"
//listOfList[1][1] == "Final string"!
   
v2
Comments
Pheonyx 17-Jul-13 10:34am
   
Yep that was what I meant, didn't notice it get changed when I posted it. :-) thanks.
ridoy 17-Jul-13 13:07pm
   
+5
Ruwaldo 18-Jul-13 2:53am
   
Thanks i got it to work...the way i was adding arrays to the list was the problem...
Rate this:
Please Sign up or sign in to vote.

Solution 1

Try:

List<list><string>> myListOfListOfStrings;</string></list>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100