C# Reference ยท Keywords and Statements
Reserved keywords
The complete list of C# reserved keywords grouped by purpose, what each one does, and how to use a keyword as an identifier with the @ prefix.
Reserved keywords are words with a fixed meaning in every C# program. You cannot use them as names for variables, methods, types or namespaces. The compiler recognizes them in any position, which is the difference from contextual keywords such as async or record.
C# has 77 reserved keywords. They are all lowercase, and the list almost never grows, because adding one would break existing programs. New features arrive as contextual keywords instead.
If you really need a reserved word as a name (for example when generating code from another system), prefix it with @: @class, @event. The @ is only a marker and is not part of the name.
string @class = "Math 101"; // legal, but avoid it in handwritten code
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.
The keywords
| Group | Keywords |
|---|---|
| Built-in types | bool byte char decimal double float int long object sbyte short string uint ulong ushort void |
| Modifiers | abstract const event extern override readonly sealed static unsafe virtual volatile |
| Access | internal private protected public |
| Declarations | class delegate enum interface namespace struct |
| Control flow | break case continue default do else for foreach goto if return switch while |
| Exceptions | catch finally throw try |
| Operators and expressions | as checked fixed is lock new operator sizeof stackalloc typeof unchecked |
| Conversions and parameters | explicit implicit in out params ref |
| Literals and references | base false null this true |
| Directives | using |
Usage notes
- Every item above is reserved everywhere. Contextual words (
var,async,await,record,where,field,required,init,with,when, and others) are not on this list. string,int,objectand the other built-in type names are aliases forSystem.String,System.Int32,System.Objectand so on. Either form is accepted, and style guides recommend the keyword form for types and the class form for static members (String.Joinorstring.Join, both work).- Several keywords have more than one job.
defaultis aswitchlabel and an expression,newcreates objects, hides members and constrains generics,inmarksforeachsources, parameters and variance,staticis a modifier, a local function modifier and ausingform, andusingis a directive and a statement. gotois rarely needed but legal (goto case,goto default, labels).- Reserved words also include
trueandfalseas literals andnullfor the null reference.voidis a type only in return positions and pointer types. fixed,stackalloc,unsafeandsizeofmostly appear in unsafe code.lockneeds a reference-type object, or aSystem.Threading.Locksince .NET 9.- Preprocessor directives such as
#ifand#regionare not keywords and are not part of the language grammar. __makeref,__reftype,__refvalueand__arglistare undocumented keywords kept for old interop code. Do not use them.