Skip to content
Tutorials Center
My learning

Topics

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.

C#
string @class = "Math 101";   // legal, but avoid it in handwritten code

Try it

C# Using @ to escape a keyword

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.

C# The keyword list as data

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, object and the other built-in type names are aliases for System.String, System.Int32, System.Object and so on. Either form is accepted, and style guides recommend the keyword form for types and the class form for static members (String.Join or string.Join, both work).
  • Several keywords have more than one job. default is a switch label and an expression, new creates objects, hides members and constrains generics, in marks foreach sources, parameters and variance, static is a modifier, a local function modifier and a using form, and using is a directive and a statement.
  • goto is rarely needed but legal (goto case, goto default, labels).
  • Reserved words also include true and false as literals and null for the null reference. void is a type only in return positions and pointer types.
  • fixed, stackalloc, unsafe and sizeof mostly appear in unsafe code. lock needs a reference-type object, or a System.Threading.Lock since .NET 9.
  • Preprocessor directives such as #if and #region are not keywords and are not part of the language grammar.
  • __makeref, __reftype, __refvalue and __arglist are undocumented keywords kept for old interop code. Do not use them.