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 trialJeff Hamilton
11,724 PointsSelecting projecting and anonymous types part 2.
Create a variable named matchingBirds and assign it a LINQ query on the birds variable that have the same Color property as the mysteryBird object. In the query, return an anonymous type with a property named BirdName and assign to it the Name property of the birds. Not sure what I am doing wrong.
var birds = new[]
{
new { Name = "Pelican", Color = "White" },
new { Name = "Swan", Color = "White" },
new { Name = "Crow", Color = "Black" }
};
var mysteryBird = new { Color = "White", Sightings = 3 };
var matchingBirds = from b in birds where b.Color == "White" select new { BirdName == b.Name};
1 Answer
Steven Parker
231,198 PointsYou need to take the challenge a bit more literally.
While "White" is indeed the color of the mysteryBird, when the challenge asks you to select the birds "that have the same Color property as the mysteryBird object" they mean you should test specifically for mysteryBird.Color.
Also, at the end of your query you have a comparison where you need an assignment:
- current code: "
new { BirdName == b.Name}
" - revised code: "
new { BirdName = b.Name}
"