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# C# Basics (Retired) Console I/O Formatting Output

David Ogburn
David Ogburn
468 Points

Code not Compiling (Suspected Treehouse Bug)

It appears that the code is not compiling due to an issue in whatever method they use to transfer my code to an actual database and thus to a C# compiler consider I am getting the following error message (I just started to learn programing so please excuse my poor terminology, I am sure this is incorrect somehow, but hopefully you get what I am trying to say)

StudentsCode.cs(8,14): error CS1525: Unexpected symbol .', expecting,', ;', or=' Compilation failed: 1 error(s), 0 warnings

So is it the Treehouse compiler as suspected or is it actually something wrong with my 2 lines of code?

string firstName = Console.ReadLine();
string Console.WriteLine(firstName);

1 Answer

28,558 Points

The error messages you see on the preview screen are generated by the C# compiler Treehouse uses, so if it complains about invalid code then it's usually correct. Errors that comes from the Treehouse code checker itself tends to show up as bummer messages or popups.

The issue with your code is that you include the string keyword on the second line. On the first line it is used to declare that the variable you are creating is a string. On the second line you are simply calling a method, not creating a variable.

Since C# thinks you are trying to declare a variable it gets confused since declaring a variable and calling a method uses quite different syntax, that is what causes the compiler error.

If you remove string like this:

string firstName = Console.ReadLine();

Then your code will work.