C# Keywords

 

Updated: July 20, 2015

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

Keywords are predefined, reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers in your program unless they include @ as a prefix. For example, @if is a valid identifier but if is not because if is a keyword.

The first table in this topic lists keywords that are reserved identifiers in any part of a C# program. The second table in this topic 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 are added as contextual keywords in order to avoid breaking programs written in earlier versions.

abstractasbasebool
breakbytecasecatch
charcheckedclassconst
continuedecimaldefaultdelegate
dodoubleelseenum
eventexplicitexternfalse
finallyfixedfloatfor
foreachgotoifimplicit
inin (generic modifier)intinterface
internalislocklong
namespacenewnullobject
operatoroutout (generic modifier)override
paramsprivateprotectedpublic
readonlyrefreturnsbyte
sealedshortsizeofstackalloc
staticstringstructswitch
thisthrowtruetry
typeofuintulongunchecked
unsafeushortusingvirtual
voidvolatilewhile

A contextual keyword is used to provide a specific meaning in the code, but it is not a reserved word in C#. Some contextual keywords, such as partial and where, have special meanings in two or more contexts.

addaliasascending
asyncawaitdescending
dynamicfromget
globalgroupinto
joinletorderby
partial (type)partial (method)remove
selectsetvalue
varwhere (generic type constraint)where (query clause)
yield

C# Reference
C# Programming Guide

Show: