how do i assign values for a list of students while doing group work?

What you need is the following line to get the Student property:

Students = g.Select(s => new Student
{
    StudentName = s.StudentName,
    StudentAge = s.StudentAge
}).ToList()

You can also replace foreach with:

var redefineSchoolDatas = group.Select(g => new RedefineSchoolData
{
    ClassName = g.Key,
    Students = g.Select(s => new Student
    {
        StudentName = s.StudentName,
        StudentAge = s.StudentAge
    }).ToList(),
}).ToList();

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top