![]() |
VOOZH | about |
Keywords or Reserved words are the words in a language that are used for some internal process or represent some predefined actions. These words are therefore not allowed to be used as variable names or objects. Doing this will result in a compile-time error.
Example:
The value of a is: 10
There are total 78 keywords in C# as follows:
abstract | do | in | protected | throw |
as | double | int | public | true |
base | else | interface | readonly | try |
bool | enum | internal | ref | typeof |
break | event | is | return | uint |
byte | explicit | lock | sbyte | ulong |
case | extern | long | sealed | unchecked |
catch | false | namespace | short | unsafe |
char | finally | new | sizeof | ushort |
checked | fixed | null | stackalloc | using |
class | float | object | static | using static |
const | for | operator | string | virtual |
continue | foreach | out | struct | void |
decimal | goto | override | switch | volatile |
default | if | params | this | while |
delegate | implicit | private |
1. Value Type Keywords: There are 15 keywords in value types which are used to define various data types.
bool | byte | char | decimal |
double | enum | float | int |
long | sbyte | short | struct |
uint | ulong | ushort |
Example:
The value of a is: 47 The value of b is: True
2.Reference Type Keywords: There are 6 keywords in reference types which are used to store references of the data or objects. The keywords in this category are: class, delegate, interface, object, string, void.
3. Modifiers Keywords: There are 17 keywords in modifiers which are used to modify the declarations of type member.
public | private | internal | protected | abstract |
const | event | extern | new | override |
partial | readonly | sealed | static | unsafe |
virtual | volatile |
Example:
Value of n1: 77
4. Statements Keywords: There are total 18 keywords which are used in program instructions.
if | else | switch | do | for |
foreach | in | while | break | continue |
goto | return | throw | try | catch |
finally | checked | unchecked |
Example:
GeeksforGeeks
5. Method Parameters Keywords: There are total 4 keywords which are used to change the behavior of the parameters that passed to a method. The keyword includes in this category are: params, in, ref, out.
6. Namespace Keywords: There are total 3 keywords in this category which are used in namespaces. The keywords are: namespace, using, extern.
7. Operator Keywords: There are total 8 keywords which are used for different purposes like creating objects, getting a size of object etc. The keywords are: as, is, new, sizeof, typeof, true, false, stackalloc.
8. Conversion Keywords: There are 3 keywords which are used in type conversions. The keywords are: explicit, implicit, operator.
9. Access Keywords: There are 2 keywords which are used in accessing and referencing the class or instance of the class. The keywords are base, this.
10. Literal Keywords: There are 2 keywords which are used as literal or constant. The keywords are null, default.
Important Points:
Example:
int a = 10; // Here int is a valid keyword
double int = 10.67; // invalid because int is a keyword
double @int = 10.67; // valid identifier, prefixed with @
int @null = 0; // valid
Illustration:
The value of a is: 10 The value of a is: 11
These are used to give a specific meaning in the program. Whenever a new keyword comes in C#, it is added to the contextual keywords, not in the keyword category. This helps to avoid the crashing of programs which are written in earlier versions.
Important Points:
add | equals | nameof | value |
alias | from | on | var |
ascending | get | orderby | when |
async | global | partial(type) | where |
await | group | partial(method) | yield |
by | into | remove | |
descending | join | select | |
dynamic | let | set |
Example:
Name: GFG Value of get is: 50 Value of set is: 70