Mid LINQ

How to filter distinct objects by a property?

How to filter distinct objects by a property?

var distinctByDept = employees

.GroupBy(e => e.Department)

.Select(g => g.First());

Explanation:

Groups employees by department and selects one employee from each group to get distinct

departments.

More from LINQ Tutorial

All questions for this course