What does "@" do in C #?

I just went to write a line ...

if (!e.PeriodicData.Keys.Contains(process))
{
}

but made a typo on "!" and click "@" instead. eg,

if (@e.PeriodicData.Keys.Contains(process))
{
}

I expected intellisense to roll over, but it is not. So I compiled and compiled it successfully.

This is not an operator, but what is @? What does it do?

+3
source share
2 answers

In this case, this is a valid name. It is used if you want to use the keyword as a variable name, for example @class.

See: What does placing @ in front of a C # variable name do?

+9
source

In this case, it just gets the variable e. It is equivalent e.

@ var , , , class. .

var @class = 1;
var @virtual = 2;
var @return = 3;

, , :

"C:\\test\\example\\"

@"C:\test\example\"
+6

All Articles