You can check this course on my website.
Keywords are predefined sets of reserved words that have special meaning for the compiler and they are cannot be used as identifiers (name of variable, interface, class, etc). For example:
Here, string
is a keyword and firstName
is a name of variable. That is, the string
keyword tells the compiler that the firstName
variable will be of the string data type.
All keywords are in lower case and can be divided into the following categories.
Type Keywords
These keywords are used to declare a data type:
bool, byte, char, class, decimal, double, enum, float, int, long, sbyte, short, string, struct, uint, ulong, ushort.
Statement Keywords
Related to program flow:
if, else, switch, case, foreach, while, do, for, in, continue, break, default, goto, yield, return, throw, try, catch, finally, checked, unchecked, fixed, lock.
Modifier and access Keywords
Allow or deny modification and access to certain parts of the code by other parts:
public, private, protected, internal, abstract, async, const, readonly, event, extern, new, override, static, virtual, volatile, unsafe, partial, sealed, this, base.
Namespace Keywords
Used to declare namespaces and other similar operations: using, . (operator), :: (operator), extern (alias)
Parameter Keywords
Applies to parameters in a method:
params, ref, out
Operator Keywords
Refer to different actions in the code: new, as, await, is, check, unchecked, typeof, sizeof, stackalloc
Literal Keywords
null, true, false, value, void
Contextual Keywords
These keywords can only be used in the specific context of the program, if they are not in a specific context, then they can be used as an identifier:
add, var, dynamic, global, get, set, value, let, from, where, select, group, into, orderby, join, in, on, equals, by, ascending, descending, async, when, where, remove.
There may not be all the keywords here, because Microsoft may add or remove some keywords, so it’s better to follow on the official website — C# keywords.
However, if you need to declare a keyword as a variable name, you can add @ before variable name.
I’ll tell you right away, even though C# allows you to name a variable in this way, but it’s better to avoid it and come up with a better name. The code will look cleaner and more understandable not only to you, but also to other programmers.
Previous article -> 1.5 .NET CLI
Next article -> 2.1 Program structure
Join to our community in Telegram — https://t.me/itifico
If you want to support me, you can buy me a cup of coffee and I will drink it when I write the next article :)
Donations list:
- Dinesh Chintalapudi — 3$
- Unknown — 5$