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 trialUlyssa Sneed
8,894 PointsWhat's the correct code look like? I have less than 24hours to figure this out and pass, new so please give solution
confused on where to begin, please give actual answer, Im ok with being told and learning from that.
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 = ourBirds.Sum(ob => ob.Sightings);
var averageSightings = ourBirds.Sum(ob => ob.Sightings);
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, Ulyssa Sneed! It looks like you're doing really well and got the .Sum
just fine! The average is going to be almost exactly the same. In fact, the only difference between the two is that you will use the .Average
aggregate method instead of the .Sum
method.
var averageSightings = ourBirds.Average(ob => ob.Sightings);
You can see where the instructor introduces the .Average
method at around 3:18 of the preceding video.
Hope this helps!