Subscribe to our YouTube Channel for more Videos

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.

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.