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 Query Operators Joins

Scott Tucker
Scott Tucker
3,765 Points

Joins Challenge help

When I used query syntax to solve this challenge I passed, but I want to be able to use and understand how to do this with method syntax. I have watched the video prior to this over and over again and I just can't seem to get it right. I believe that my resultSelector is wrong but I don't know exactly how to fix it.

CodeChallenge.cs
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,
                            m => m.Name,
                            y => y.Name,
                            bird => myBirds);

1 Answer

Steven Parker
Steven Parker
229,670 Points

You're close. But the final argument to .Join (the resultSelector) should be a Func<TOuter, TInner, TResult>

This means it takes two arguments and returns a result (which in this case can be either of the arguments).

So if we modify that call like this, your method syntax version should also pass the challenge:

var ourBirds = myBirds.Join(yourBirds,
                            m => m.Name,
                            y => y.Name,
                            (m, y) => m);

Happy coding! Β  -sp:sparkles:

Scott Tucker
Scott Tucker
3,765 Points

This worked. Thank you so much!