Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTojo Alex
Courses Plus Student 13,331 PointsI don't know what is wrong
Please could I have an answer for this challenge .
var myBirds = new List<Bird>
{
new Bird { Name = "Cardinal", Color = "Red", Sightings = 3 },
new Bird { Name = "Dove", Color = "White", Sightings = 2 },
new Bird { Name = "Robin", Color = "Red", Sightings = 5 }
};
var yourBirds = new List<Bird>
{
new Bird { Name = "Dove", Color = "White", Sightings = 2 },
new Bird { Name = "Robin", Color = "Red", Sightings = 5 },
new Bird { Name = "Canary", Color = "Yellow", Sightings = 0 }
};
var ourBirds = myBirds.Join(yourBirds,
mb => mb.Name,
yb => yb.Name,
(mb, yb) => (mb));
var sumOfSightings = new { Enumerable.Sum<ourBirds>};
2 Answers
Tim Strand
22,458 PointsYou are supposed to sum the sightings in ourBirds using linq. Your current is
var sumOfSightings = new { Enumerable.Sum<ourBirds>};
however linq sum works as this <list>.Sum(); so if we have an object to sum it would work <list>.Sum(o => o.[object key] so if we think of this in terms of our challenge <list> can be replaced with ourBirds since our birds is a list of objects we need to specify the obj key to use in this case Sightings thus we arrive at the below answer.
var sumOfSightings = ourBirds.Sum(ob => ob.Sightings);
Tojo Alex
Courses Plus Student 13,331 Pointswell explained thanks.