I have been using C# and .NET for over 10 years now and recently I have started to dig here and there for little details of the language and the framework. The other day, I came across an interesting sort of new way of using the
"@". And I say sort of new because I had used this before but I never really internalize it.
The most common use of the
@ symbol that I have encounter is to use verbatim string literals (as described in the string reference for C#). This basically means that you don’t need to escape the backslash as it ignores escape sequences:
Also, in MVC land, you make heavy use of the
@ symbol when you are using Razor as a View Engine. So you have probably written code like this:
When you start to work with HTML Helpers, you learn that an Anonymous Object can be sent as a parameter and its properties will become HTML attributes on the client side. Also, you can see that you can use
@class to specify a CSS class to be rendered.
Well, this is what I didn’t know. The
@ symbol in front of the
class is actually in the C# specification as a way to use reserved words as identifiers. You it is perfectly valid to declare variable names like:
So as they say, you learn something new every day :-)
Photo from Dustin Gaffke