0

I just found out something like this which works in C# code.

foreach (var item in list)
{
   Console.WriteLine(@item);
}

Can anyone explain how is this possible - I have not found any documentation in ECMA for this.

tomkuj
  • 81
  • 1
  • 5
  • Maybe it was asp razor generated cshtml file ? – MajkeloDev Sep 25 '15 at 12:57
  • Is list a list of strings? I'm pretty sure it behaves like the normal @ before string literals. – g williams Sep 25 '15 at 12:59
  • 1
    It's so you can use keywords as variable names. Like `@this` won't function as a keyword. – kevintjuh93 Sep 25 '15 at 12:59
  • I guess compiler is taking Console.WriteLine(@item) as a => Console.WriteLine(@""+item); Both the codes posses same result. This code works same for both line of codes. ------- var list=new List(); list.Add("1"); list.Add("2"); list.Add("3"); foreach (var item in list) { Console.WriteLine(@""+item); Console.WriteLine(@item); } – Mukesh Kumar Sep 25 '15 at 13:11
  • `@identifier` is mentioned in ECMA 334 - **9.4.2 Identifiers** – Richard Schneider Sep 25 '15 at 13:15
  • But this is not "int @class;" this is before some existing variable name so this is not what you refer to Richard, IMO – tomkuj Sep 25 '15 at 13:23

0 Answers0