Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have ArrayList of ArrayLists, how can I display the values of each ArrayList. For example if I have arraylist a that contain arraylists (b,c,d), how can I read the values of ArrayLists b, and c and d.
Posted

1 solution

All you have to do is loop through your ArrayList and then loop through your ArrayList that you're looping through :)
C#
ArrayList arr = new ArrayList();
arr.Add(new ArrayList(new[] { "value 1.1", "value 1.2" }));
arr.Add(new ArrayList(new[] { "value 2.1", "value 2.2" }));
arr.Add(new ArrayList(new[] { "value 3.1", "value 3.2" }));
foreach (ArrayList innerArr in arr)
{
	foreach (object element in innerArr)
	{
		// Do something with the elements.
	}
}
May I suggest you take a look at the List<T>[^] class though?
 
Share this answer
 
v2
Comments
CPallini 20-May-14 15:59pm    
Well, good loop!
Sander Rossel 20-May-14 16:35pm    
Thanks, one of the finest I've written :-)

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