I want to-
- Sort students in ascending order within each group (Example: Jack, John & Peter in Group 1, etc)
- Arrange all sorted groups in ascending order by their first item (Example: Group 3, 2 and 1)
Collection
public class StudentInfo
{
public string Student { get; set; }
public string University { get; set; }
public int GroupID { get; set; }
public bool IsQualified {get; set;}
}
List<StudentInfo> studentsList = new List<StudentInfo>();
StudentsList.Add( new StudentInfo { Student="John", University="ABC", GroupID = 1, IsQualified=False});
StudentsList.Add( new StudentInfo { Student="Jack", University="DEF", GroupID = 1, IsQualified=False} );
StudentsList.Add( new StudentInfo { Student="Peter", University="GHI", GroupID = 1, IsQualified=False} );
StudentsList.Add( new StudentInfo { Student="Olivia", University="ABC", GroupID = 2, IsQualified=False} );
StudentsList.Add( new StudentInfo { Student="Donald", University="JKL", GroupID = 2, IsQualified=False} );
StudentsList.Add( new StudentInfo { Student="Adam", University="GHI", GroupID = 3, IsQualified=False} );
StudentsList.Add( new StudentInfo { Student="Jacob", University="ABC", GroupID = 3, IsQualified=False} );
Expected Output
Group 3:
Adam
Jacob
Group 2:
Donald
Olivia
Group 1:
Jack
John
Peter
Pseudo Code
var results = studentsList
.GroupBy(x => x.GroupID)
.SelectMany(g => g.OrderBy(x => x.Student)).ToList();
I don't know what to write beyond this. Please help me.