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 trialPhuQuy Pham
9,588 PointsLINQ Query
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.
Can someone tell me what's wrong with my code:
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 List<int> NumbersGreaterThanFive = new List<int>()
{
IEnumerable<int> NumbersGreaterThanFive = from n in _numbers
where n>5
select n;
}
}
}
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 List<int> NumbersGreaterThanFive = new List<int>()
{
IEnumerable<int> NumbersGreaterThanFive = from n in _numbers
where n>5
select n;
}
}
}
1 Answer
Steven Parker
231,275 PointsYou're close, but:
- the method definition syntax should not have an assignment operator (or anything between it and the ()'s)
- the type is defined here as
List<int>
, but the instructions ask forIEnumerable<int>
- the method needs to return the result.