C# Querying With LINQ Functional Programming in C# LINQ Method Syntax

LINQ Method Syntax challenge

In the preceding video the LINQ query

from b in birds
where b.Color == "Red"
select b;

is refactored in 3 different ways:

birds.Where((b) => b.Color == "Red");
birds.Where((b) => { return b.Color == "Red"; });
birds.Where(b => b.Color == "Red");

I've tried all 3 variants in the challenge and for each I get the error message: Bummer! Did you use

And that's it. Just Did you use

Did I use what?

I'm currently out of thoughts? If anyone has a suggestion it would be welcome! Thanks.

NumberAnalysis.cs
using System.Collections.Generic;
using System.Linq;

namespace Treehouse.CodeChallenges
{
    public class NumberAnalysis
    {
        private List<int> _numbers;
        public NumberAnalysis()
        {
            _numbers = new List<int> { 2, 4, 6, 8, 10 };
        }

        public IEnumerable<int> NumbersGreaterThanFive()
        {
            //return from n in _numbers where n > 5 select n;  //LINQ query

            //return _numbers.Where((n) => n > 5);  //version 1
            //return _numbers.Where((n) => { return n > 5; });  //version 2a
            //_numbers.Where((n) => { return n > 5; });  //version 2b
            return _numbers.Where(n => n > 5); //version 3

        }
    }
}
James Churchill
James Churchill
Treehouse Teacher

Did you try removing your commented out code from the NumbersGreaterThanFive method?

1 Answer

Steven Parker
Steven Parker
170,315 Points

Congratulations, you've discovered a bug ("Did you use"). :beetle: You might want to report this to Treehouse Support.

But James has the right idea. I also had trouble with commented code in this course.

:point_right: Delete your comments and you should pass the challenge.