Find all objects using lambda
3 answers
It's as simple as SelectMany :
Projects each element of a sequence onto an IEnumerable and flattens the resulting sequences into one sequence.
var kids = people.SelectMany(p => p.Kids);
(If you want List<Kid>
instead IEnumerable<Kid>
, just call .ToList()
the result.)
+13
source to share
You can use SelectMany extension method
var kids = new List(people.SelectMany(person => person.Kids));
+4
source to share