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) Perfect Refactoring

Ira Buckman
Ira Buckman
1,447 Points

Compile error - I don't get it!

Line #1 of my C# program is a comment which reads: //using System; This indicates the namespace is "System" so we don't have to explicitly code it. So System.Console.Write can be shortened to Console.Write

When compiled this error results: (1,12): error CS1525: Unexpected Symbol ‘.’, expecting ‘,’, ‘;’, or ‘=’

How can line #1 cause an error if it's a comment?

btw - I previously compiled this program successfully with the same comment in line #1.

Any insights are greatly appreciated.

Thanks.

Hi Ira,

Can you include the rest of your code in markdown?

Steven Parker
Steven Parker
231,236 Points

Something else has changed in your build environment. The best way to share the code and build environment is to make a snapshot of your workspace and post the link to it here.

3 Answers

Ira Buckman
Ira Buckman
1,447 Points

Thanks to all the responders. Actually, I figured out the problem. I mistakenly compiled the .exe file instead of the .cs file and that caused the subsequent compile errors of the .cs file. I think I got around the problem by running the .exe file. I sure won't do that again! ;-)

Steven Parker
Steven Parker
231,236 Points

That certainly explains things. I was pretty sure the comment wouldn't cause that specific error, but I was waiting to see the snapshot to determine the actual issue.

Congratulations on resolving it yourself, and happy coding!

Kevin Gates
Kevin Gates
15,053 Points

If you truly have this on line one: //using System; This indicates the namespace is "System" so we don't have to explicitly code it. So System.Console.Write can be shortened to Console.Write

Then it's because you commented out "using System".

You probably want something more like this:

//This indicates the namespace is "System" so we don't have to explicitly code it. So System.Console.Write can be shortened to Console.Write
using System;
James Thomas
James Thomas
6,452 Points

As above. You need the "using" namespace reference for system, unless you want to strongly type it each time. The wrong thing is commented out. Comments are never compiled, and therefore anything written after "//" in the same line will not have an effect on the program in any way.

Steven Parker
Steven Parker
231,236 Points

"Comments are never compiled" is what makes me wonder about the cause of the "Unexpected Symbol" error — I'd sure like to take a peek at that workspace!