8
In the response code of this question on Soen I found an unfamiliar statement line on C#. I tested this line and it works, but I didn’t understand the meaning of this character @
behind the member’s name.
// declara "@foo" como uma string com o valor "bar"
var @foo = "bar";
// declara "@abc" como um tipo anônimo com sub valores
var @abc = new {a = 32, b = 64, c = 128}
And I also noticed that it works with classes and types:
class @Program {
void @Main (string[] args) {
...
But by passing his name over the names, Intellisense Visual Studio removes the @ of the names:
And I can also call the members with or without the @
:
void @Foo () {
Bar();
@Bar();
}
void @Bar() {
...
}
And even if the @bar
did not have the @
, may be called with him in the same way.
And I can also declare a method called void
:
void @void () { ... }
I know that in Visual Basic, you can declare members with names already reserved by the language using [ ... ] in names. That’s the same thing, only in C#? Or it has another function besides that?
In Asp Net MVC we have this in the "namespace" parameter in the route definition call. This is to escape a reserved word .
– Wallace Maxters