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 Quantifiers

please help

Create a variable named allBlueBirds and write a LINQ query using the All method to assign a boolean value if all of the Bird objects in the birds list have the value "Blue" in the Color property.

CodeChallenge.cs
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 = false; if (birds.Any(b => b.Color == "Blue")) { anyBlueBirds = true; }
var allBlueBirds = false; if (birds.all(b => b.Color == "Blue")) 

2 Answers

Steven Parker
Steven Parker
231,198 Points

You're almost there. But you still need to add the code block after the "if" statement to perform the assignment, similar to what you did on the previous line for task 1.

And you need to fix your spelling of the method name "all" (with a lower-case "a") to be "All" (with a capital "A").

Kevin Gates
Kevin Gates
15,053 Points

Remember, your Any, All, and Contains methods all return a boolean result. So for the previous quiz question, it was:

var anyBlueBirds = birds.Any(b=>b.Color == "Blue");

(Rhetorical question for those unsure: ) Based on that, what do you suspect the correct syntax would be for "All"?