C# keywords are reserved words with predefined meanings used by the compiler to perform specific operations. They are part of the C# language syntax and generally cannot be used as identifiers unless the @ prefix is used.
- Keywords cannot normally be used as identifiers such as variable, method, class, or object names.
- C# also has contextual keywords, which have special meaning only in specific contexts.
- Examples include int, class, if, return, public, etc.
using System;
class Geeks {
static void Main()
{
const int limit = 20;
int marks = 25;
if (marks >= limit) {
Console.WriteLine("Passed");
}
else {
Console.WriteLine("Failed");
}
}
}
Output
Passed
Explanation:
- using imports a namespace.
- class defines a class named Program.
- static declares a method that belongs to the class itself.
- void indicates that the method does not return a value.
- const declares a constant.
- int specifies an integer data type.
- if and else control which block of code executes.
Types of Keywords
C# keywords are classified into two main categories based on how they are interpreted by the compiler.

1. Reserved Keywords
Reserved keywords have predefined meanings in C# and cannot normally be used as names for variables, classes, or methods.
Examples include int, class, if, while, return, and public.
int age = 25;
if (age >= 18)
{
Console.WriteLine("Eligible");
}
Here, int declares an integer variable, while if checks a condition.
2. Contextual Keywords
Contextual keywords have special meanings only in particular programming contexts. Outside those contexts, they can often be used as identifiers.
Examples include var, async, await, record, partial, and where.
var name = "GeeksforGeeks";
Console.WriteLine(name);
Here, var tells the compiler to infer the local variable's type from its initializer. In this case, the inferred type is string.
List of C# Keywords
C# keywords can be grouped according to their common purposes, such as declaring data types, controlling execution, handling exceptions, and defining classes.
The following sections organize the main reserved keywords into functional categories.
Data Type Keywords
Used to define variables and specify the kind of data they can hold.
| Keyword | Usage |
|---|---|
| bool | Represents a Boolean value, true or false. |
| byte | Represents an 8-bit unsigned integer. |
| sbyte | Represents an 8-bit signed integer. |
| char | Represents a 16-bit Unicode character. |
| short | Represents a 16-bit signed integer. |
| ushort | Represents a 16-bit unsigned integer. |
| int | Represents a 32-bit signed integer. |
| uint | Represents a 32-bit unsigned integer. |
| long | Represents a 64-bit signed integer. |
| ulong | Represents a 64-bit unsigned integer. |
| float | Represents a single-precision floating-point number. |
| double | Represents a double-precision floating-point number. |
| decimal | Represents a high-precision decimal number. |
| string | Represents a sequence of characters. |
| object | Represents the base type from which all C# types ultimately derive. |
| void | Specifies that a method does not return a value. |
Control Flow Keywords
Used to control the execution flow of a program.
| Keyword | Usage |
|---|---|
| if | Executes code when a condition is true. |
| else | Defines an alternative block when an if condition is false. |
| switch | Selects a block of code based on a value. |
| case | Defines an individual branch in a switch statement. |
| default | Defines the block executed when no case matches. |
| for | Starts a for loop. |
| foreach | Iterates through elements in a collection. |
| while | Starts a while loop. |
| do | Starts a do-while loop. |
| break | Terminates the nearest loop or switch. |
| continue | Skips to the next iteration of a loop. |
| goto | Transfers execution to a labeled statement. |
| return | Exits from a method and optionally returns a value. |
Exception Handling Keywords
Used for handling runtime errors and exceptions.
| Keyword | Usage |
|---|---|
| try | Defines a block of code in which exceptions may occur. |
| catch | Handles an exception thrown by a try block. |
| finally | Defines code that executes after try/catch. |
| throw | Throws an exception. |
Object-Oriented Keywords
Used to define classes, objects, inheritance, interfaces, and related object-oriented features.
| Keyword | Usage |
|---|---|
| class | Declares a class. |
| interface | Declares an interface. |
| struct | Declares a value-type structure. |
| enum | Declares a set of named constants. |
| delegate | Defines a delegate type for referencing methods. |
| new | Creates an object or invokes a constructor. |
| this | Refers to the current object. |
| base | Refers to members of the base class. |
| abstract | Declares a class or member that requires implementation by derived types. |
| sealed | Prevents inheritance or further overriding. |
| virtual | Allows a derived class to override a member. |
| override | Provides a new implementation of an inherited virtual or abstract member. |
Access Control Keywords
Define the accessibility of classes and their members.
| Keyword | Usage |
|---|---|
| public | Accessible from anywhere that can access the containing type. |
| private | Accessible only within the containing type. |
| protected | Accessible within the containing type and derived types. |
| internal | Accessible within the current assembly. |
Namespace and Using Keywords
Used to organize code and access types from namespaces.
| Keyword | Usage |
|---|---|
| namespace | Defines a scope for organizing related types and namespaces. |
| using | Imports a namespace or defines other using directives. |
C# namespaces organize related types and can also be declared using file-scoped syntax.
Modifier Keywords
Used to define additional characteristics of types and members.
| Keyword | Usage |
|---|---|
| static | Indicates that a member belongs to the type rather than an instance. |
| const | Declares a compile-time constant. |
| readonly | Prevents a field from being assigned except in permitted initialization contexts. |
| volatile | Indicates that a field can be modified by multiple threads or external mechanisms. |
| extern | Indicates that a method is implemented externally. |
| unsafe | Enables unsafe code operations. |
Parameter and Reference Keywords
Used with method parameters and references.
| Keyword | Usage |
|---|---|
| ref | Passes a parameter by reference. |
| out | Passes a parameter by reference for output. |
| in | Passes a parameter by readonly reference. |
| params | Allows a method to accept a variable number of arguments. |
Type and Conversion Keywords
| Keyword | Usage |
|---|---|
| as | Performs a compatible reference, nullable, or boxing conversion. |
| is | Checks whether an object is compatible with a specified type or pattern. |
| typeof | Obtains the System.Type object for a type. |
| sizeof | Obtains the size of a value type in bytes in permitted contexts. |
| default | Produces the default value of a type or specifies a default case. |
Operator Keywords
| Keyword | Usage |
|---|---|
| operator | Declares an overloaded operator. |
| implicit | Defines an implicit user-defined conversion. |
| explicit | Defines an explicit user-defined conversion. |
Memory Management and Synchronization Keywords
| Keyword | Usage |
|---|---|
| lock | Acquires an exclusive lock for a critical section. |
| fixed | Prevents the garbage collector from relocating a variable during an unsafe operation. |
| stackalloc | Allocates memory on the stack. |
Checked and Unchecked Keywords
| Keyword | Usage |
|---|---|
| checked | Enables overflow checking for integral arithmetic operations. |
| unchecked | Disables overflow checking for integral arithmetic operations. |
Contextual Keywords
Contextual keywords have special meaning only in particular contexts and may be used as ordinary identifiers outside those contexts.
| Keyword | Usage |
|---|---|
| var | Enables implicitly typed local variables. |
| dynamic | Defers type checking for certain operations until runtime. |
| async | Marks a method, lambda, or local function as asynchronous. |
| await | Suspends an asynchronous operation until the awaited task completes. |
| nameof | Produces the name of a symbol as a string. |
| record | Declares a record type. |
| required | Indicates that a member must be initialized when an object is created. |
| partial | Allows a type or member declaration to be split across multiple declarations. |
| get | Defines the getter accessor of a property or indexer. |
| set | Defines the setter accessor of a property or indexer. |
| init | Defines an accessor that can assign a property during object initialization. |
| value | Represents the value being assigned in a property or indexer setter. |
| yield | Produces values from an iterator. |
| with | Creates a copy of an object with specified changes. |
| when | Specifies a filter condition in certain contexts. |
| where | Specifies generic constraints or filters query results. |
LINQ Query Keywords
C# query expressions use contextual keywords such as from, where, select, group, orderby, join, let, into, on, equals, by, ascending, and descending.
| Keyword | Usage |
|---|---|
| from | Specifies the data source of a query. |
| where | Filters elements based on a condition. |
| select | Specifies the result of a query. |
| group | Groups query results. |
| orderby | Sorts query results. |
| join | Combines elements from two data sources. |
| let | Introduces a variable inside a query. |
| into | Stores an intermediate query result. |
| on | Specifies the join condition. |
| equals | Specifies equality between join keys. |
| by | Specifies a grouping key. |
| ascending | Sorts query results in ascending order. |
| descending | Sorts query results in descending order. |
Special Literals
C# provides predefined literal values that represent special values.
| Literal | Usage |
|---|---|
| true | Represents the Boolean value true. |
| false | Represents the Boolean value false. |
| null | Represents a null reference or null value where applicable. |
Keywords vs Identifiers
| Feature | Keywords | Identifiers |
|---|---|---|
| Definition | Reserved or context-specific words with predefined meanings in C# | User-defined names for variables, methods, classes, etc. |
| Purpose | Define the syntax and structure of C# programs | Identify program elements |
| Can be Modified | No | Yes |
| Usage as Variable Name | Not normally allowed | Allowed |
| Predefined by C# | Yes | No |
| Examples | int, class, if, return | studentName, calculateSum, Employee |
| Case Sensitive | Yes | Yes |
| Compiler Meaning | Defined by the C# language | Defined by the programmer |
Important: Unlike Java's final, C# uses const, readonly, and other mechanisms for different forms of immutability; and unlike Java, C# has the @ escape mechanism for using keywords as identifiers.