Keywords

Keywords are character tokens that define the syntax rules of the C# language.

A keyword is a set of built-in terms native to C#. These words carry special functional meanings, so you cannot reuse them for other coding purposes such as variable names or function names—doing so will create ambiguous logic. Take the word int as an example: it stands for integer data types in C#. If you attempt to declare a variable named int like bool int = 12;, the compiler will fail to parse your code, simply because int is reserved for dedicated language functionality.

There are two core rules governing keywords

Keywords cannot be directly used as variable names or other identifiers, with the sole exception of prefixing the keyword with the @ symbol. All standard C# keywords are written entirely in lowercase; by contrast, built-in .NET type names follow PascalCase capitalization.

abstractconstexternintoverridesizeoftypeof
ascontinuefalseinterfaceparamsstackallocuint
basedecimalfinallyinternalprivatestaticulong
booldefaultfixedisprotectedstringunchecked
breakdelegatefloatlockpublicstructunsafe
bytedoforlongreadonlyswitchushort
casedoubleforeachnamespacerefthisusing
catchelsegotonewreturnthrowvirtual
charenumifnullsbytetruevoid
checkedeventimplicitobjectsealedtryvolatile
classexplicitinoperatorwhenwhile

Globally reserved terms, never usable as raw identifiers in any scenario; the @ prefix is mandatory.

int @int; // Valid syntax
int int;  // Triggers compilation errorCode language: JavaScript (javascript)

Contextual Keywords

Contextual Keywords

Contextual keywords only function as reserved words within specific syntax blocks. Unlike standard keywords, they can be freely used as identifiers elsewhere in your source code.

addascendingasyncawaitbydescendingdynamic
equalsfromgetglobalgroupininto
joinletonorderbypartialremoveselect
setvaluevarwhereyield

Only take keyword meaning in dedicated syntax structures; you may name variables directly with them in other places

int var; // Permitted, var is not treated as a keyword outside type inference logic
var num = 10; // var acts as a keyword here for implicit type deductionCode language: JavaScript (javascript)

All highlighted terms from the prior example fall under the category of keywords.

Keywords

Leave a Reply

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