Reputation: 12915
I have Parents and Children, and Children have Names. I'm trying to get a List of strings from a Parent that contains the Names of each of a given Parent's Children. Something like:
List<string> Names = Parent.Children.Foreach(child => "add child.name to array");
How can I achieve this?
Upvotes: 0
Views: 89
Reputation: 9508
Use select
List<string> Names = Parent.Children.Select(child => child.Name).ToList();
Upvotes: 2