views:

157

answers:

4

I have a web application project called Site, and in it is a folder called SITE (I know, not the best naming conventions, but that's another story).

When I check the designer generated code it starts like this:

namespace Site.@__SITE__ {

Why is the at sign added? I can remove it and the project compiles and runs fine. Also, with or without the at sign, the actual namespace is Site.__SITE__.

Thanks!

+9  A: 

The @ symbol is a way of allowing names which conflict with C# keywords to be used in a C# application. All names in C# which begin with __ are reserved for future use. As a result whenever the CodeDom emits code where a name is prefixed with __, it will emit a @ sign in order to guarantee the name will be legal since it may conflict with a future C# keyword.

The code you are seeing is likely following the same rules or just emitted as part of the CodeDom

JaredPar
A: 

They do that in case you name your "site" something that is a reserved keyword ... so if your site name is "class" :-P the @ symbol would allow that name to be used as the namespace

Joel Martinez
+2  A: 

The @ prefix is used when the identifier clashes with a built-in keyword. Presumably double-underscore identifiers are reserved for future use, so the designer is playing safe.

Daniel Earwicker
A: 

When an @ occurs before an identifier in C# the compiler considers the following string to be an identifier even if the string is a keyword.

This is just a safety measure for automatically generated identifiers.

Michael Burr