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 trial

C# Querying With LINQ Now You're Querying Selecting, Projecting and Anonymous Types

help plz

var birds = new[] { new { Name = "Pelican", Color = "White" }, new { Name = "Swan", Color = "White" }, new { Name = "Crow", Color = "Black" } }; var mysteryBird = new { Name = "Bird" , Color = "White", Sightings = 3 }; var matchingBirds = new { Name = BirdName.Name; Color = mysteryBird.Color };

CodeChallenge.cs
var birds = new[] 
{ 
    new { Name = "Pelican", Color = "White" }, 
    new { Name = "Swan", Color = "White" }, 
    new { Name = "Crow", Color = "Black" } 
};
var mysteryBird   = new { Name = "Bird" , Color = "White", Sightings = 3 };
var matchingBirds = new {
    Name = BirdName.Name;
    Color = mysteryBird.Color
};

2 Answers

James Churchill
STAFF
James Churchill
Treehouse Teacher

Shawn,

The matchingBirds variable should hold the result of a LINQ, not another anonymous object. Your LINQ query should filter the list of birds and then project the results into a collection of anonymous objects.

Here's what that should look like:

var birds = new[] 
{ 
    new { Name = "Pelican", Color = "White" }, 
    new { Name = "Swan", Color = "White" }, 
    new { Name = "Crow", Color = "Black" } 
};
var mysteryBird   = new { Name = "Bird" , Color = "White", Sightings = 3 };
var matchingBirds = birds.Where(b => ???).Select(b => ???);

I've omitted part of the implementation... you'll need to replace the ??? bits with the actual code that is required.

Thanks ~James

thanks james