1

是否可以用 lambdas 而不是 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;
        }
      }
    }
4

1 回答 1

2

是的:

return Sections.SelectMany(s => s.Questions.SelectMany(q => q.SurveyAnswers));
于 2012-04-16T23:25:20.033 回答