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

Aaron Selonke
Aaron Selonke
10,323 Points

What was that!

Why do the groupings return { Status = Vulnerable, Sightings = System.Collections.G eneric.List`1[BirdWatcher.Sighting] }

when calling the Count(), what exactly is being counted?

1 Answer

Matthew Hill
Matthew Hill
7,798 Points

When the results of the first query are grouped by status, all of the sightings associated with that status are turned into a list. So if you have:

Endagered - 1 sighting Endagered - 3 sightings Endagered - 2 sightings

You end up with:

Endagered - 1 sighting, 3 sightings, 2 sightings

As for your second question. Remember that sighting is a class in and of itself. This means that in the bird class it is represented as a list of sightings. You therefore need to do a count on the list for each bird in the group, then sum those together.

Hope that makes sense! Matt