Click here to Skip to main content
15,880,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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>>

What Pheonyx means is probably

C#
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:

C#
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"!
 
Share this answer
 
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...
Try:

C#
List<list><string>> myListOfListOfStrings;</string></list>
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900