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

Nathan Yebgui
Nathan Yebgui
10,331 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
James Churchill
Treehouse Teacher


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