I know the title is not great but I think the code will come across a lot better.
Say I have the following class:
public class Test
{
public List<Object> ObjectList = new List<Object>;
}
Now let’s say I have a list<Test> listOfTest that has 100 items in its list, and each Test object in the list has 100 items in its List<Object> ObjectList list.
Can I use LINQ, Lambda expression or anything to quickly get all the Objects’s from every Test object?
Currently I have to do the following:
var items = new List<Object>();
foreach(var testobj in listOfTest)
{
items.AddRange(testObj.ObjectList);
}
I do know I could do listOfTest.foreach() but it really comes down to still needing the foreach.
I personally do NOT like this and think it is a hack almost and there must be a better way to do this. So the question is basically, is there a better way to do this?
How about: