Get internal list from C # list list

I am working with C # and I have the following

List<List<UserObj>> obj; 

How to get the internal list ( List<UserObj> ) of an obj object?

Thanks.

+4
source share
4 answers

There is no internal list - there are many of them.

You can get specific, for example: obj[0] .

Alternatively, you can combine the contents of all lists into one long list:

 var result = obj.SelectMany(x => x).ToList(); 
+9
source
 List<UserObj> users = obj[myindex]; 

or

 foreach(List<UserObj> users in obj) { foreach(UserObj user in users) { // now we have an individual user from our list of lists } } 
+7
source

Am I simplifying this?

 foreach( var innerList in outerList ) { foreach( var item in innerList ) { // do whatever } } 
+2
source

This is a list of listings. You can list obj list. Each item has a List<UserObj> value.

 foreach (List<UserObj> innerList in obj) { // do something with innerlist } 
+1
source

All Articles