What are the C# keywords?
Category: Introduction, viewed: 4K time(s).
Keywords are predefined, reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers in your program unless they include @ as a prefix. The table below lists keywords that are reserved identifiers in any part of a C# program.
| Keyword | Description |
|---|---|
abstract |
The abstract modifier indicates that the thing being modified has a missing or incomplete implementation. The abstract modifier can be used with classes, methods, properties, indexers, and events. |
as |
The as operator is used to perform certain types of conversions between compatible reference types. |
base |
The base keyword is used to access members of the base class from within a derived class. |
bool |
The bool keyword is an alias of System.Boolean. It is used to declare variables to store the Boolean values, true and false. |
break |
The break statement terminates the closest enclosing loop or switch statement in which it appears. Control is passed to the statement that follows the terminated statement, if any. |
byte |
The byte keyword is an alias of System.Byte. It denotes an integral type that stores values of unsigned 8 bit integer in the range of 0 to 255. |
case |
The switch statement is a control statement that selects a switch section to execute from a list of candidates. Each switch section contains one or more case labels and a list of one or more statements. |
catch |
The try-catch statement consists of a try block followed by one or more catch clauses, which specify handlers for different exceptions. |
char |
The char keyword is used to declare a Unicode character in the range of U+0000 to U+FFFF. Unicode characters are 16-bit characters that are used to represent most of the known written languages throughout the world. It is an alias of System.Char. |
checked |
The checked keyword is used to explicitly enable overflow checking for integral-type arithmetic operations and conversions. |
class |
The class keyword is used to declare classes. |
const |
The const keyword is used to modify a declaration of a field or local variable. It specifies that the value of the field or the local variable is constant, which means it cannot be modified. |
continue |
The continue statement passes control to the next iteration of the enclosing iteration statement in which it appears. |
decimal |
The decimal keyword indicates a 128-bit data type. Compared to floating-point types, the decimal type has more precision and a smaller range, which makes it appropriate for financial and monetary calculations. |
default |
The default keyword can be used in the switch statement to specify the default label. In generic code the default keyword specifies the default value of the type parameter. This will be null for reference types and zero for value types. |
delegate |
A delegate is a reference type that can be used to encapsulate a named or an anonymous method. The declaration of a delegate type is similar to a method signature. It has a return value and any number of parameters of any type. |
do |
The do statement executes a statement or a block of statements enclosed in {} repeatedly until a specified expression evaluates to false. |
double |
The double keyword signifies a simple type that stores 64-bit floating-point values. |
else |
The if statement selects a statement for execution based on the value of a Boolean expression. If true the if block executes otherwise the else block will be executed. |
enum |
The enum keyword is used to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list. |
event |
The event keyword is used to declare an event in a publisher class. |
explicit |
The explicit keyword declares a user-defined type conversion operator that must be invoked with a cast. |
extern |
The extern modifier is used to declare a method that is implemented externally. |
false |
The false keyword is used as an overloaded operator or as a literal. |
finally |
The finally block is useful for cleaning up any resources allocated in the try block as well as running any code that must execute even if there is an exception. Control is always passed to the finally block regardless of how the try block exits. |
fixed |
The fixed statement prevents the garbage collector from relocating a movable variable. The fixed statement is only permitted in an unsafe context. fixed can also be used to create fixed size buffers. |
float |
The float keyword signifies a simple type that stores 32-bit floating-point values. |
for |
The for loop executes a statement or a block of statements repeatedly until a specified expression evaluates to false. The for loop is useful for iterating over arrays and for sequential processing. |
foreach |
The foreach statement repeats a group of embedded statements for each element in an array or an object collection that implements the System.Collections.IEnumerable or System.Collections.Generic.IEnumerable<T> interface. |
goto |
The goto statement transfers the program control directly to a labeled statement. |
if |
The if statement selects a statement for execution based on the value of a Boolean expression. If true the if block executes otherwise the else block will be executed. |
implicit |
The implicit keyword is used to declare an implicit user-defined type conversion operator. Use it to enable implicit conversions between a user-defined type and another type, if the conversion is guaranteed not to cause a loss of data. |
in |
The foreach statement repeats a group of embedded statements for each element in an array or an object collection that implements the System.Collections.IEnumerable or System.Collections.Generic.IEnumerable<T> interface. |
int |
The int keyword denotes an integral type that stores values of signed 32 bit integer. |
interface |
An interface contains only the signatures of methods, properties, events or indexers. A class or struct that implements the interface must implement the members of the interface that are specified in the interface definition. |
internal |
The internal keyword is an access modifier for types and type members. Internal types or members are accessible only within files in the same assembly. |
is |
The is keyword is used to checks if an object is compatible with a given type. |
lock |
The lock keyword marks a statement block as a critical section by obtaining the mutual-exclusion lock for a given object, executing a statement, and then releasing the lock. |
long |
The long keyword denotes an integral type that stores values of signed 64 bit integer. |
namespace |
The namespace keyword is used to declare a scope. This namespace scope lets you organize code and gives you a way to create globally unique types. |
new |
The new keyword can be used as an operator, a modifier, or a constraint. |
null |
The null keyword is a literal that represents a null reference, one that does not refer to any object. |
object |
The object type is an alias for System.Object in the .NET Framework. |
operator |
The operator keyword is used to overload a built-in operator or to provide a user-defined conversion in a class or struct declaration. |
out |
The out contextual keyword is used in two contexts: as a parameter modifier in parameter list. In generic type parameter declarations in interfaces and delegates. |
override |
The override modifier is required to extend or modify the abstract or virtual implementation of an inherited method, property, indexer, or event. |
params |
The params keyword lets you specify a method parameter that takes a variable number of arguments. |
private |
The private keyword is a member access modifier. Private access is the least permissive access level. Private members are accessible only within the body of the class or the struct in which they are declared. |
protected |
The protected keyword is a member access modifier. A protected member is accessible within its class and by derived class instances. |
public |
The public keyword is an access modifier for types and type members. Public access is the most permissive access level. There are no restrictions on accessing public members. |
readonly |
The readonly keyword is a modifier that you can use on fields. When a field declaration includes a readonly modifier, assignments to the fields introduced by the declaration can only occur as part of the declaration or in a constructor in the same class. |
ref |
The ref keyword causes arguments to be passed by reference. The effect is that any changes to the parameter in the method will be reflected in that variable when control passes back to the calling method. |
return |
The return statement terminates execution of the method in which it appears and returns control to the calling method. It can also return an optional value. If the method is a void type, the return statement can be omitted. |
sbyte |
The sbyte keyword indicates an integral type that stores values of signed 8 bit integer with range from -128 to 127. |
sealed |
When applied to a class, the sealed modifier prevents other classes from inheriting from it. |
short |
The short keyword denotes an integral data type that stores values of signed 16 bit integer. |
sizeof |
The sizeof keyword is used to obtain the size in bytes for an unmanaged type. |
stackalloc |
The stackalloc keyword is used in an unsafe code context to allocate a block of memory on the stack. |
static |
The static modifier is used to declare a static member, which belongs to the type itself rather than to a specific object. The static modifier can be used with classes, fields, methods, properties, operators, events, and constructors, but it cannot be used with indexers, destructors, or types other than classes. |
string |
The string type represents a sequence of zero or more Unicode characters. string is an alias for System.String in the .NET Framework. |
struct |
A struct type is a value type that is typically used to encapsulate small groups of related variables, such as the coordinates of a rectangle or the characteristics of an item in an inventory. |
switch |
The switch statement is a control statement that selects a switch section to execute from a list of candidates. Each switch section contains one or more case labels and a list of one or more statements. |
this |
The this keyword refers to the current instance of the class and is also used as a modifier of the first parameter of an extension method. |
throw |
The throw statement is used to signal the occurrence of an anomalous situation (exception) during the program execution. |
true |
The true keyword is used as an overloaded operator or as a literal. |
try |
The try-catch statement consists of a try block followed by one or more catch clauses, which specify handlers for different exceptions. |
typeof |
The typeof keyword is used to obtain the System.Type object for a type. |
uint |
The uint keyword signifies an integral type that stores values of unsigned 32 bit integer. |
ulong |
The ulong keyword denotes an integral type that stores values of unsigned 64 bit integer. |
unchecked |
The unchecked keyword is used to suppress overflow-checking for integral-type arithmetic operations and conversions. |
unsafe |
The unsafe keyword denotes an unsafe context, which is required for any operation involving pointers. |
ushort |
The ushort keyword indicates an integral data type that stores values of unsigned 16 bit integer. |
using |
The using keyword has two major uses: as a directive, when it is used to create an alias for a namespace or to import types defined in other namespaces. As a statement, when it defines a scope at the end of which an object will be disposed. |
virtual |
The virtual keyword is used to modify a method, property, indexer, or event declaration and allow for it to be overridden in a derived class. |
void |
When used as the return type for a method, void specifies that the method does not return a value. |
volatile |
The volatile keyword indicates that a field might be modified by multiple threads that are executing at the same time. |
while |
The while statement executes a statement or a block of statements until a specified expression evaluates to false. |