3

I just went to write the line...

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

but did a typo on "!" and hit "@" instead. eg

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

I was expecting intellisense to flipout but it didn't. So I compiled and it compiled successfully.

Its not an operator, so what is "@"? What does it do?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
DJA
  • 661
  • 1
  • 9
  • 25

2 Answers2

9

In this case its a valid name. It is used if you want to use a keyword as a variable name like @class.

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

Community
  • 1
  • 1
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • 2
    That being said -- don't do this. It's exceptionally confusing to use keywords as variable names. – Joe Mar 12 '11 at 01:52
  • 1
    In some cases its unavoidable - especially with MVC's HtmlHelpers that take HTML attributes. – Daniel A. White Mar 12 '11 at 01:56
  • An answer like this is a really good sign that you should have voted to close the question as a duplicate. I'm not really sure why you didn't; you don't seem to be adding any information beyond that given in the answers to the other question. – Cody Gray - on strike Mar 12 '11 at 08:49
7

In this case it is just getting the variable e. It is equivalent to e.

The @ symbol before a var is used if you want to call a variable class for instance. To use reserved words as variables.

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

As for strings it uses the literal, for example:

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

Is equivalent to

@"C:\test\example\"
BrunoLM
  • 97,872
  • 84
  • 296
  • 452