C# Querying With LINQ Query Operators Conversion Operators

Brad Wagner
Brad Wagner
8,855 Points

C#'s Conversion Operator 'ToList()' doesn't seem to be compiling properly for coding challenge (unless my answer is bad)

In 'Querying With LINQ', I'm doing the last Challenge of 'Query Operators '- 3rd section, of which I'm doing the last task (2 of 2). My answer for that task is the second line below:

var numbers = Enumerable.Range(0,10);
numbers.ToList();

I'm getting this error message when submitting my answer: ERROR: The 'numbers' variable isn't a List. Did you use ToList() to cast the numbers enumerable to a list?

I've ran the same code in the Treehouse Repl and I believe I'm answering correctly because 'numbers.ToList()' is returning a List<int> after execution.

Through the implicit type 'var' and the .ToList() operator it should be converting it to a List. Is something wrong with compilation or am I incorrect in my answer? If the latter is the case, I say ahead of time, 'oopsy'.

CodeChallenge.cs
var numbers = Enumerable.Range(0,10);
numbers.ToList();

2 Answers

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 49,663 Points

To convert numbers I would assume there would be an assignment involved. Try

numbers = numbers.ToList();
Brad Wagner
Brad Wagner
8,855 Points

Thought that might work too and I tried that also (an assignment). I got the same error as above, but thanks for answering.
I think I just have to move on to the next lesson and forget about this problem.

Brad Wagner
Brad Wagner
8,855 Points

I'll give it a shot again here.

Brad Wagner
Brad Wagner
8,855 Points

It worked! I probably mistakenly typed something else the first time I tried the assignment. Thanks.