In C# Keywords are predefined words with special meaning to the compiler. These are reserved identifiers used in C# for specific purposes. They cannot be used as identifiers (name) for a variable, class or interface in a program unless @ is included as the prefix to make them verbatim identifiers.
E.g., switch is a keyword we cannot use switch as an identifier, but we can use @switch as an identifier.
We can distribute C# Keywords into below given categories.
They are used to access base class of an object or another class. They include:
Access Modifier Keywords
These are used to restrict access to class members and member functions outside class. These include:
Some other words are used to add some specific meaning in code. They are called contextual keywords. They are also used as identifiers, including:
- partial (method)
- remove select
- when (filter condition)
- where (generic type constraint)
They apply to the current instance of an object.
Method Parameter Keywords
These keywords are applied to parameters of a function/ method. They include:
They are keywords that indicate who can modify types and types members. They also prevent a particular portion of code to be changed by other parts.
Here is a list of these:
These keywords are applied with namespace and related operators.
- extern alias
- :: operator
Query keywords are contextual keywords used in LINQ queries.
These keywords are related to program flow are used to control the flow of a program. i.e., they are used to run a particular portion of code at when some condition is met. They include:
They are used for data types. i.e., to define or specify the type for an identifier that it will hold which type of data.
As pointed in the image above we used a reserved keyword as an identifier. And in the picture below we accessed its member output is shown.