C# Querying With LINQ Now You're Querying Using Query Syntax

help please

Create a public method in the NumberAnalysis class called NumbersGreaterThanFive that returns an IEnumerable<int>. Inside the method, use LINQ query syntax to return only the numbers in the _numbers field that are greater than 5.

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 };
           IEnumerable<int>NumbersGreaterThanFive = from n in _numbers where n >5 select n;
        }
    }
}

2 Answers

Howdy!

Instead of creating a method you created an Enumerable with that name in the constructor. You should create a method that returns that Enumerable.

Good luck!

SPOILER

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

thank you very much

Allan Clark
MOD
Allan Clark
Treehouse Moderator 10,534 Points

First, you are required to create a new method for this task. You currently have your linq query in the constructor method. Being that it gives you the name and return type the method signature should look like this:

public IEnumerable<int> NumbersGreaterThanFive()

Your query looks correct so I will leave the implementation up to you!

Happy coding!!!

thank you