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.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...