I have an object that looks something like this:
public class Student { public string Name { get; set; } public int Grade { get; set; } }
I would like to create the following query: group grades by student name, sort each group of students by grade, and group orders by maximum grade in each group.
So it will look like this:
A 100 A 80 B 80 B 50 B 40 C 70 C 30
I created the following query:
StudentsGrades.GroupBy(student => student.Name) .OrderBy(studentGradesGroup => studentGradesGroup.Max(student => student.Grade));
But this returns IEnumerable IGrouping , and I cannot sort the list inside, unless I do this in another foreach query and add the results to another list using AddRange .
Is there a nicer way to do this?
c # linq sql-order-by group-by
Rita Feb 16 2018-11-11T00: 00Z
source share