When it comes to programming languages, C# is a powerhouse in the .NET ecosystem. As with any language, understanding its keywords is crucial for effective coding. But how many C# keywords are there, and what are they? Let's dive in.
C# Keywords: An Overview
C# keywords are reserved words that have special meanings to the compiler. They form the building blocks of the language, enabling you to declare variables, control program flow, and interact with the .NET runtime. Understanding these keywords is fundamental to mastering C#.
How Many C# Keywords Are There?
As of C# 9.0, there are 79 keywords in the C# language. This number has grown over time as new features have been added to the language. Here's a breakdown of the keywords by category:

- Access modifiers: 5 (public, private, protected, internal, protected internal)
- Cast-related keywords: 3 (is, as, is, checked, unchecked)
- Control flow: 14 (if, else, switch, while, do, for, break, continue, goto, return, yield, throw, try, catch, finally)
- Exception handling: 4 (throw, catch, finally, checked)
- Iteration: 4 (foreach, in, do, while)
- Object-oriented programming: 12 (class, struct, interface, enum, this, base, new, virtual, override, abstract, sealed, explicit)
- Type-related keywords: 12 (bool, byte, short, int, long, float, double, decimal, string, object, void, dynamic)
- Other keywords: 17 (true, false, null, default, const, ref, out, in, fixed, stackalloc, unmanaged, unsafe, async, await, partial, global, nameof)
New Keywords in C# 9.0
C# 9.0 introduced several new keywords, including:
- init: Used to declare initializers for record types.
- record: Introduces a new reference type that simplifies data modeling.
- required: Used to specify that a parameter has a default value, but it's required if a different value is provided.
C# Keywords vs. Identifiers
It's essential to understand the difference between C# keywords and identifiers. Keywords have special meanings in the language, while identifiers are names given to entities like variables, methods, and classes. You cannot use a keyword as an identifier, but you can use an identifier as a keyword if it's enclosed within backticks (`).
C# Keywords List
Here's a complete list of C# keywords, grouped by category:

| Access modifiers | Cast-related keywords | Control flow |
|---|---|---|
| public | is | if |
| private | as | else |
| protected | is | switch |
| internal | checked | while |
| protected internal | unchecked | do |
| Exception handling | Iteration | Object-oriented programming |
| throw | foreach | class |
| catch | in | struct |
| finally | do | interface |
| checked | while | enum |
| Type-related keywords | Other keywords | |
| bool | true | |
| byte | false | |
| short | null | |
| int | default | |
| long | const | |
| float | ref | |
| double | out | |
| decimal | in | |
| string | fixed | |
| object | stackalloc | |
| void | unmanaged | |
| dynamic | unsafe | |
| async | async | |
| await | await | |
| partial | partial | |
| global | global | |
| nameof | nameof |
Understanding and being able to recognize C# keywords is a crucial step in mastering the language. This list should serve as a helpful reference as you continue your C# learning journey. Happy coding!























