Mid From PDF LINQ 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
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details