0

I am trying to extract a list of Goals from within a list of Students using this method

 public List<Goal> GetGoalsForTeacher(int userId)
        {
            var students = GetStudentsForTeacher(userId);
            var result = students.Select(e => e.Goals).ToList();
            return result

        }

However, I need it to return a List, but it is returning a List<IList>. Has anyone any idea on how I would convert this or make it a List initially?

culdaffe
  • 39
  • 5

1 Answers1

1

You're looking for the SelectMany() method.

var result = students.SelectMany(e => e.Goals).ToList();
StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315