C# Keywords and Contextual Keywords: A Comprehensive Guide
Understand the difference between C# keywords and contextual keywords. This tutorial provides a complete list, explains their usage, and clarifies when the `@` symbol is needed to use them as identifiers, enhancing your understanding of C# syntax and semantics.
C# Keywords and Contextual Keywords
C# keywords are reserved words with special meanings in the language. They cannot be used as identifiers (variable names, class names, etc.) unless prefixed with the `@` symbol. Contextual keywords have special meaning only within specific contexts.
C# Keywords
These keywords are reserved and cannot be used as identifiers without the `@` prefix:
abstract |
as |
base |
bool |
break |
byte |
case |
catch |
char |
checked |
class |
const |
continue |
decimal |
default |
delegate |
do |
double |
else |
enum |
event |
explicit |
extern |
false |
finally |
fixed |
float |
for |
foreach |
goto |
if |
implicit |
in |
int |
interface |
internal |
is |
lock |
long |
namespace |
new |
null |
object |
operator |
out |
override |
params |
private |
protected |
public |
readonly |
ref |
return |
sbyte |
sealed |
short |
sizeof |
stackalloc |
static |
string |
struct |
switch |
this |
throw |
true |
try |
typeof |
uint |
ulong |
ushort |
unchecked |
unsafe |
using |
virtual |
void |
volatile |
while |
C# Contextual Keywords
Contextual keywords have special meaning only in specific parts of the code (like within LINQ queries):
add |
ascending |
descending |
dynamic |
from |
get |
global |
group |
into |
join |
let |
orderby |
partial |
remove |
select |
set |
value |
yield |