What are the keywords in C#? – Programming, Pseudocode Example, C# Programming Example
C#

What are the keywords in C#?

C# contains reserved words that have special meaning for the compiler. These reserved words are called “keywords”. Keywords cannot be used as an identifier (name of a variable, class, interface, etc.).

C# keywords or distributed in the following categories.

  • Modifiers
  • Access modifiers
  • Statement
  • Method Parameter
  • Operator
  • Namespace
  • Access
  • Literal
  • Type
  • Query
  • Contextual

Modifiers Keywords in C#

Modifier keywords are those keywords that indicate modify the type and type members. These keywords allow are to prevent certain parts of a program from being modified by another part below are modifiers keyword.

Modifiers KeywordsDescription
abstractIf a class marked with abstract it’s mean this class can only be intended to be a base class of others
asyncThe async keyword indicates that the method is asynchronous
constThe keyword indicates that the value of the variable can not be modified
eventThis keyword used for the declaration of an event
externFor the external implementation of the method
newThis keyword explicitly hides the member
overrideThis keyword provides the new implementation of the virtual member
partialThis is used for the declaration of the partial class
readonlyThis keyword indicates that the field can only be assigned as a part of the declaration
sealedIf a class marked with sealed it means that class can not be inherited
staticA member that itself belongs to a type
unsafeFor the declaration of unsafe context
virtualIndicate that the implementation can be changed by an override method
volatileIndicate that a field cannot be modified in a program

Access modifiers in C#

Access modifiers are defined at the stage of the declaration of a class, method, properties, or members. these keywords define the accessibility of the class and its member.

For a class or struct, the default access modifier is private and for the interface and enum is public.

You can find some access modifiers from the below table

Access modifiersDescription
PublicAccess is not limited to a type or type member. This keyword provides complete visibility.
PrivateDefault access modifier type. Access is limited only code in the same class or struct can access it
Protectedlimited access to the containing type or types derived from the containing class
InternalLimited access to the current assembly only

Statement Keyword in C#

Basically, keywords under this category are program instructions. these keywords are executed in sequence. The below table lists the C# statement keywords.

Statement Keyword
if
else
switch
case
do
for
foreach
in
while
break
continue
default
goto
return
yield
throw
try
catch
finally
checked
unchecked
fixed
lock

statement keywords further divide into the following categories.

CategoryC# Keywords
Selection statementif,else,switch,case
itteration statementdo, for,foreach,while,in
jump statementbreak, continue, default, goto, return, yield
exception handlingthrow, try catch, try-finally, try-finally-catch
checked and uncheckedchecked, unchecked
fixed statementfixed
lock statementlock

Method Parameter in C#

Those keywords are applied as the parameter of the method

Method Parameter
params
ref
out

Namespace Keywords in C#

Those keywords are applied with the namespace. Within a namespace, we can define more of the following types.

  • Using
  • . operator
  • :: operator
  • extern alias

Operator Keyword in C#

C# provides operator keywords a number of them support built-in types and allow us to perform operations. Which are listed below the table.

Operator KeywordDescription
asThe conversion of an object into the compatible type
awaitThe suspension of asynchronous function to compute the await task
isThis keyword checks the type of an object during the run time.
newThe creation of a new object, or for the hides an inherited member.
sizeofThis keyword uses to obtain the size of a given object.
typeofReturns the system.type of object.
stackallocThe allocation of the block of memory.
checkedThis keyword is used to explicitly enable overflow checking for integral-type arithmetic operations and conversions
uncheckedThis keyword is used to suppress overflow-checking for integral-type arithmetic operations and conversions

Access Keywords in C#

Access keywords are used to access the containing class or the base class of an object or class.

Access Keywords
base
this

Literal Keywords in C#

Literal keywords apply to the current instance or value of an object.

Literal Keywords
null
false
true
value
void

Type Keywords in C#

Type keywords are used for data types.

Type Keywords
bool
byte
char
class
decimal
double
enum
float
int
long
sbyte
short
string
struct
uint
ulong
ushort

Contextual Keywords in C#

Contextual keywords are considered as keywords, only if used in specific contexts. They are not reserved and so can be used as names or identifiers.

These keywords cannot be converted into the default keyword colors which is blue when we use them in c# as an identifier.

Contextual Keywords
add
var
dynamic
global
set
value

Query Keywords in C#

Query keywords are contextual keywords used in query expressions.

Query KeywordsDescription
fromdefine the range of a variable or data source
wherefilter the element in the boolean expression.
selectreturn sequence
groupa specified group query result according to a specified key-value
intoan identifier that can serve as a reference to the results of a join, group or select clause
orderbyascending or descending order of the return result
joinfor the join of the data source
letthe range of the variable
ina keyword in the join clause
ona keyword in the join clause
equalsa keyword in the join clause
bya keyword in the group clause
ascendinga keyword in an orderby clause
descendinga keyword in an orderby clause

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.