731
A keyword is a reserved word. You cannot use it as a variable name, constant name etc.
In C# keywords cannot be used as identifiers. However, if we want to use the keywords as identifiers, we may prefix the keyword with @ character.
Reserved keywords
The following table lists the available reserved keywords in the c# programming language.
abstract | bool | continue | decimal | default |
event | explicit | extern | char | checked |
class | const | break | as | base |
delegate | is | lock | long | num |
byte | case | catch | false | finally |
fixed | float | for | as | foreach |
goto | if | implicit | in | int |
interface | internal | do | double | else |
namespace | new | null | object | operator |
out | override | params | private | protected |
public | readonly | sealed | short | sizeof |
ref | return | sbyte | stackalloc | static |
string | struct | void | volatile | while |
true | try | switch | this | throw |
unchecked | unsafe | ushort | using | using static |
virtual | typeof | uint | ulong | out (generic modifier) |
Contextual keywords
In c#, Contextual keywords can be used as an identifier in a limited program context, which can be outside of the context.
Generally, whenever the new keywords are added to the C# language, those are treated as Contextual keywords to avoid breaking c# programs that we wrote in older versions.
The following table lists the available Contextual Keywords in the c# programming language.
add | alias | async | await | dynamic |
from | get | orderby | ascending | descending |
group | into | join | let | nameof |
global | partial | set | remove | select |
value | var | when | Where | yield |