Skip to content

Latest commit

 

History

History
174 lines (167 loc) · 8.13 KB

File metadata and controls

174 lines (167 loc) · 8.13 KB
description C# Keywords: Find the reference material for the predefined keywords and contextual keywords defined in the C# language.
title C# Keywords and contextual keywords
ms.date 06/05/2026
f1_keywords
cs.keywords
helpviewer_keywords
keywords [C#]
C# language, keywords
Visual C#, keywords
@ keyword
ms.custom updateeachrelease

C# keywords

Keywords are predefined, reserved identifiers that have special meanings to the compiler. You can't use them as identifiers in your program unless you prefix them with @. For example, @if is a valid identifier, but if isn't because if is a keyword.

[!INCLUDEcsharp-version-note]

The first table in this article lists keywords that are reserved identifiers in any part of a C# program. The second table lists the contextual keywords in C#. Contextual keywords have special meaning only in a limited program context and can be used as identifiers outside that context. Generally, as new keywords are added to the C# language, they're added as contextual keywords to avoid breaking programs written in earlier versions.

:::row::: :::column::: abstract
as
base
bool
break
byte
case
catch
char
checked
class
const
continue
decimal
default
delegate
do
double
else
enum
:::column-end::: :::column::: event
explicit
extern
false
finally
fixed
float
for
foreach
goto
if
implicit
in
int
interface
internal
is
lock
long
:::column-end::: :::column::: namespace
new
null
object
operator
out
override
params
private
protected
public
readonly
ref
return
sbyte
sealed
short
sizeof
stackalloc
:::column-end::: :::column::: static
string
struct
switch
this
throw
true
try
typeof
uint
ulong
unchecked
unsafe
ushort
using
virtual
void
volatile
while
:::column-end::: :::row-end:::

Contextual keywords

A contextual keyword provides a specific meaning in the code, but it isn't a reserved word in C#. Some contextual keywords, such as partial and where, have special meanings in two or more contexts.

:::row::: :::column::: add
allows
alias
and
ascending
args
async
await
by
closed
descending
dynamic
equals
:::column-end::: :::column::: extension
field
file
from
get
global
group
init
into
join
let
managed (function pointer calling convention)
nameof
:::column-end::: :::column::: nint
not
notnull
nuint
on
or
orderby
partial (type)
partial (member)
record
remove
required
safe
:::column-end::: :::column::: scoped
select
set
unmanaged (function pointer calling convention)
unmanaged (generic type constraint)
value
var
when (filter condition)
where (generic type constraint)
where (query clause)
with
yield
:::column-end::: :::row-end:::