C# Querying With LINQ Querying the BirdWatcher Data Sightings of Endangered Birds

Nathan Yebgui
Nathan Yebgui
10,318 Points

a much easier way

birds.GroupBy( b => b.ConservationStatus).Select( g => new { Status = g.Key, Sightings = g.Sum( s => s.Sightings.Count()) }); you can add birds.Where(b => b.ConservationStatus != "..." && .. etc) at the beginning to only get the desired statuses.

1 Answer

James Churchill
STAFF
James Churchill
Treehouse Teacher

Nathan,

Thanks for the feedback! As you noted, there's almost always more than one way to write a query. And often the solution that doesn't use a join will be easier to understand too.

Thanks ~James