Mid LINQ

How to group and order groups by count descending?

How to group and order groups by count descending?

var groupOrder = employees

.GroupBy(e => e.Department)

.OrderByDescending(g => g.Count());

foreach (var group in groupOrder)

Console.WriteLine($"{group.Key} has {group.Count()} employees");

More from LINQ Tutorial

All questions for this course