Contextual Keywords in C#

If we need to use an identifier that has the same name of the keyword in C#, you can do so by prefixing the identifier with the @symbol.

An example for this can be string where i can have an have the implementation similar to the one shown below

string @string =”senthil”;

Even without the @ symbol, some keywords can be used an identifiers directly. Some of these keywords include

  • add
  • dynamic
  • partial
  • where
  • async
  • from
  • select
  • remove
  • global
  • var

The above contextual keywords are only a partial list. There are few more contextual keywords in C# as well.

For example, below is a valid identifier in C#.

int dynamic = 2;

The contextual keywords are valid based on the context in which it is used.