RobVious
RobVious

Reputation: 12915

Getting a list of strings from a parent's children

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

Answers (1)

Simon C
Simon C

Reputation: 9508

Use select

List<string> Names = Parent.Children.Select(child => child.Name).ToList();

Upvotes: 2

Related Questions