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 Functional Programming in C# LINQ Method Syntax

can't solve challenge 2 of 2

Add a new method named ReverseNumbers that has a return type of IEnumerable<int> and uses a LINQ query to return the _numbers variable in reverse order. Bummer! Did you use the method 'OrderByDescending' to return the '_numbers' variable in reverse? Restart Preview Get Help Recheck work NumberAnalysis.cs

5 1 using System.Collections.Generic; 2 using System.Linq; 3 ā€‹ 4 namespace Treehouse.CodeChallenges 5 { 6 public class NumberAnalysis 7 { 8 private List<int> _numbers; 9 public NumberAnalysis() 10 { 11 _numbers = new List<int> { 2, 4, 6, 8, 10 }; 12 } 13 ā€‹ 14 public IEnumerable<int> NumbersGreaterThanFive() 15 { 16

17 return _numbers.Where(n => n > 5); 18 ā€‹ 19 } 20 public IEnumerable<int> ReverseNumbers() 21 { 22

23 return _numbers.Where(n => n < 5);
24 ā€‹ 25 } 26 } 27 }

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 _numbers.Where(n => n > 5); 

        }
           public IEnumerable<int> ReverseNumbers()
        {

              return _numbers.Where(n => n < 5);  

        }
    }
}

1 Answer

Stephen Gheysens
Stephen Gheysens
11,935 Points

Hi Shawn,

Great work on passing the first task, LINQ syntax can take a little time to get used to. For the Task 2, instead of using the Where method, there's another that you can use that will Order the elements By Descending values. Let me know if you need any more help!

Thanks, Stephen