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 trialshawn khah
15,082 Pointshelp me
Challenge Task 1 of 2
Create a variable named anyBlueBirds and write a LINQ query using the Any method to assign a boolean value if there are any Bird objects in the birds list that have the value "Blue" in the Color property. Bummer! Did you set 'anyBlueBirds' to a value? Restart Preview Get Help Recheck work CodeChallenge.cs
1 var birds = new List<Bird> 2 { 3 new Bird { Name = "Cardinal", Color = "Red", Sightings = 3 }, 4 new Bird { Name = "Dove", Color = "White", Sightings = 2 }, 5 new Bird { Name = "Robin", Color = "Red", Sightings = 5 }, 6 new Bird { Name = "Canary", Color = "Yellow", Sightings = 0 }, 7 new Bird { Name = "Blue Jay", Color = "Blue", Sightings = 1 }, 8 new Bird { Name = "Crow", Color = "Black", Sightings = 11 }, 9 new Bird { Name = "Pidgeon", Color = "White", Sightings = 10 } 10 }; 11 var anyBlueBirds = new List<Birds> 12 { 13 anyBlueBirds.Any(b=> b.Color == "Blue"); 14 } 15 ā
var birds = 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 },
new Bird { Name = "Canary", Color = "Yellow", Sightings = 0 },
new Bird { Name = "Blue Jay", Color = "Blue", Sightings = 1 },
new Bird { Name = "Crow", Color = "Black", Sightings = 11 },
new Bird { Name = "Pidgeon", Color = "White", Sightings = 10 }
};
var anyBlueBirds = new List<Birds>
{
anyBlueBirds.Any(b=> b.Color == "Blue");
}
2 Answers
Steven Parker
231,248 PointsYou should apply the Any method to the existing birds variable.
This statement is creating anyBlueBirds, so it would not make sense to reference it yet.
And you can assign the new variable directly from the result of the Any (you don't need a "new").
shawn khah
15,082 Pointsthanks steven