C# C# Basics (Retired) Perfect Refactoring

Ira Buckman
Ira Buckman
1,438 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
170,475 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,438 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
170,475 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
13,625 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,451 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
170,475 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!