Back to Procedural Programming
Below is the complete code for the Back to Procedural Programming Try It Out! problem.
List<Person> parentsOfTeenagers = new List<Person>();
foreach (Person person in people)
{
foreach (Person child in person.Children)
{
if (child.Age > 13 && child.Age < 30)
{
parentsOfTeenagers.Add(person);
}
}
}
Overall, this isn’t too bad. It’s still fairly understandable, though I’d say it’s substantially less clear than the original LINQ query. It’s definitely longer, and involves more nested statements.