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#

Tojo Alex
PLUS
Tojo Alex
Courses Plus Student 13,331 Points

This is taking forever to check my work

In this challenge : https://teamtreehouse.com/library/querying-with-linq/now-youre-querying/selecting-projecting-and-anonymous-types-2 on task 2 of 2 it is taking a long time to check my work any solutions?

Steven Parker
Steven Parker
231,261 Points

Please show your complete code, and move this question into the correct category (C#).

8 Answers

Steven Parker
Steven Parker
231,261 Points

So it does appear to be a code issue. I agree it's a bug in the challenge to just time out, but it won't happen when you provide a correct answer.

The instructions say "Create a variable named matchingBirds and assign it a LINQ query ...". So you'll need to create a LINQ expression using the "birds" variable.

Then it says, "In the query, return an anonymous type with a property named BirdName and assign to it the Name property of the birds.". So you had the right idea about creating the anonymous object, but instead of the "Color" property you'll assign 'BirdName" with the "Name" property. And this will be done for each matching bird using the LINQ query. The final result will be a collection of anonymous objects instead of just one.

Another hint: when constructing my LINQ query I used both "Where" and "Select".

Steven Parker
Steven Parker
231,261 Points

Here's a few more hints:

  • you won't be adding to "birds", but using it to select items to assign to "matchingBirds"
  • the instructions ask for you to use a LINQ query to do this
  • the LINQ methods of "Where" and "Select" may be useful (or the "query syntax" equivalents)
  • the "BirdName" property should be a Name, not a Color
  • "mysteryBird" will be used only for comparing, not for assigning
  • as a last resort, look at answers to other questions about this same challenge
Tojo Alex
PLUS
Tojo Alex
Courses Plus Student 13,331 Points

This is actually a bug that I reported to treehouse support. Every time in challenge 2 of 2 the compiler freezes.

Steven Parker
Steven Parker
231,261 Points

It could also be a side-effect of the code. Show your code here and we can check it.

Tojo Alex
PLUS
Tojo Alex
Courses Plus Student 13,331 Points

Sure :

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 = new {BirdName = mysteryBird.Color};
Tojo Alex
PLUS
Tojo Alex
Courses Plus Student 13,331 Points

When there is an error it gives me a compiler message though when there isn't the challenge freezes then after a short period of time asks me to reload the challenge then the whole thing starts again (This all happens in challenge 2).

Tojo Alex
PLUS
Tojo Alex
Courses Plus Student 13,331 Points

This has been reported to treehouse support though they do not have an issue on their end and I did try it on different devices though it is the same story.

Tojo Alex
PLUS
Tojo Alex
Courses Plus Student 13,331 Points

I re watched the video though I don't know where I'm going with this :

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 = new {BirdName = mysteryBird.Color};
birds.Add(matchingBirds);
Steven Parker
Steven Parker
231,261 Points

I added a few more hints to my answer :arrow_heading_up:

Tojo Alex
PLUS
Tojo Alex
Courses Plus Student 13,331 Points

Before you answered again I did a few more changes :

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 => ???);
Steven Parker
Steven Parker
231,261 Points

You were definitely on the right track there!

Tojo Alex
PLUS
Tojo Alex
Courses Plus Student 13,331 Points

Hold on I found out the answer thanks!!!!!!!!!!