Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# Querying With LINQ Query Operators Conversion Operators

Brad Wagner
Brad Wagner
9,379 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

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

numbers = numbers.ToList();
Brad Wagner
Brad Wagner
9,379 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
9,379 Points

I'll give it a shot again here.

Brad Wagner
Brad Wagner
9,379 Points

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

Strange. I tried it and it passed.