Reputation: 45
would it be possible to express the following block of code with lambdas instead of foreachs?
IEnumerable<BODSurveys.SurveysAnwer> resp = new List<SurveysAnwer>();
foreach (var section in Sections)
{
foreach (var question in section.Questions)
{
foreach (var answer in question.SurveysAnwers)
{
yield return answer;
}
}
}
Upvotes: 1
Views: 113
Reputation: 241583
Yes:
return Sections.SelectMany(s => s.Questions.SelectMany(q => q.SurveyAnswers));
Upvotes: 2