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