C# Keywords

Array Collections File String Windows VB.NET Algorithm ASP.NET Cast Class Compression Convert Data Delegate Directive Enum Exception If Interface Keyword LINQ Loop Method .NET Number Regex Sort StringBuilder Struct Switch Time Value

Arrow illustration

Keywords, along with other tokens, form the syntax of a programming language. There exist 77 reserved keywords in the C# programming language. There are additional terms that act as keywords in some contexts. Reserved keywords are the language's core.

Most languages use fixed character strings such as for, do, and if, as punctuation marks or to identify constructs. Such character strings are called keywords. Aho et al., p. 79

Reserved

Each keyword is listed in alphabetical order on the left side and a link is provided to a relevant article on this site on the right side. The list was taken from the C# Programming Language Specification third edition.

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

Overview: This page shows all the C# keywords available. It provides links to each keyword.

Note: Reserved keywords cannot be used as variable identifiers or member names in the C# language. They are part of the language grammar that is used to parse programs. They are the core of the C# language's textual representation.

Contextual

Programming tip

Some keywords are only considered keywords when used in certain contexts. These contexts include query expressions. Contextual keywords are still usable as identifiers, unlike reserved keywords.

Contextual Keyword

Accessibility

Private keyword

Programs can become fantastically complex creatures after enough features are added. The principle of information hiding allows you to prevent certain parts of a program from accessing other parts. In the C# language, information hiding is introduced with accessibility keywords and domains.

Accessibility is specified with an accessibility modifier on each class member. These keywords can be used with static members as well. The default accessibility of a member is private. To minimize restrictions to access, you can use the public modifier. The protected modifier is in between those two.

public protected internal protected internal private

Review: Information hiding can make a program of unmanageable complexity manageable. It introduces synthetic barriers into your program's structure that can greatly reduce the possibility of spaghetti code and needlessly involved logic between discrete parts.

This section provides information

Token

We explore the concept of tokens in the C# programming language. Tokens are understood at the lexical level. They are an important part of how the language is processed.

Token Explanation

Summary

.NET Framework information

Keywords are essential to understanding the C# programming language. On the surface, they seem to be the entire language. However, the intricate interactions between these keywords and the lower-level parts of the .NET Framework—such as the virtual execution engine and the intermediate language—may represent a greater part.

Dot Net Perls