public class MyClass {
List<MyOtherClass> myInnerList;
}
Let's say I have the following declared somewhere else:
List<MyClass> myOuterlist;
How would I quickly generate a list of the myInnerLists in C# using VS2005?
public class MyClass {
List<MyOtherClass> myInnerList;
}
Let's say I have the following declared somewhere else:
List<MyClass> myOuterlist;
How would I quickly generate a list of the myInnerLists in C# using VS2005?
Why not a simple for loop?
List<List<MyOtherClass>> innerLists = new List<List<MyOtherClass>>();
for (int i = 0; i < myOuterList.Count; i++)
{
innerLists.Add(myOuterList[i].myInnerList);
}
if you wanted to flatten the lists into a list of MyOtherClass
:
List<MyOtherClass> list = m.SelectMany(x => x.myInnerList).ToList();