-2

I am new to C# programming and was reading in C Sharp 2010 for programmers and this interrupted me.

Identifiers may also be preceded by the @ character. This indicates that a word should be interpreted as an identifier, even if it’s a keyword (e.g., @int). This allows C# code to use code written in other .NET languages where an identifier might have the same name as a C# keyword.

1-Can anyone explain what will the interrupter do if a @character was used with an example please, and how it is different than identifying without the @character.

2- how can it be used in other .NET languages

Hassan Nahhal
  • 31
  • 1
  • 8

1 Answers1

5

The @ character allows you to use reserved keywords as identifier names:

int @int = 1;

Or

void M(object[] @params) 
{ }

Without it, the compiler would emit an error (CS1041) that you are attempting to use a keyword as an identifier name:

Identifier expected, 'keyword' is a keyword. A reserved word for the C# language was found where an identifier was expected. Replace the keyword with a user-specified identifier.

A list of reserved keywords can be found here.

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
  • can you please explain how can i use @ character in other .NET langauges – Hassan Nahhal May 10 '15 at 20:39
  • yes ,the author said that C# code can use other .net languages codes . so how can i benefit of this – Hassan Nahhal May 10 '15 at 20:47
  • What the author ment is that you can leverage this with other .NET languages where C# keywords are totally valid identifier names. For example, if an F# library uses `params` as an identifier name, you could bypass it by adding the `@` character to that variable. – Yuval Itzchakov May 10 '15 at 20:52