C# Keywords

C# Keywords are known as predefined sets of reserved words that have special meaning for the compiler in any language. C# keywords can’t be used as identifiers i.e variable name, class name, etc. Keywords are preset, reserved identifiers that the compiler interprets differently. If they don’t start with @, they can’t be utilised as identifiers in your software. @if, for example, is a valid identifier; however, if is not because it is a keyword.

As an example,

long mobileNo;  

mobileNo is a variable, and long is a keyword (identifier). In C#, the term long has a specific meaning; for example, it is used to declare variables of the type long, and this function cannot be changed.

Long, int, char, and other watchwords can’t be used as identifiers, either. We can’t have something along these lines:

long  long  ; 

C# has 79 watchwords in total. Every single one of these catchphrases is written in lowercase letters. Here’s a complete list of all C# watchwords.

Types of C# Keywords:

C# Keywords are divided into two types:

  1. Reserve Keywords
  2. Contextual Keywords

1- Reserved keywords:

Reserved keywords in C# are known as the words which are reserved for the compiler in any part of the program.

Given below is the list of Reserved Keywords:

isasif in do
tryref externcharchecked
classconstbreakboolbase
delegateabstractlocklongnum
bytecasecatchfalsefinally
fixedfloatforasulong
gotocontinueimplicitdecimalint
interfaceinternaldefaultdoubleelse
namespacenewnullobjectoperator
outoverrideparamsprivateprotected
publicreadonlysealedshortsizeof
explicitreturnsbytestackallocstatic
stringstructvoidvolatilewhile
trueeventswitchthisthrow
uncheckedunsafeushortusingusing static
virtualtypeofuintout
using System;
public class Student
{
public void DisplayInfo(string Name)
{
Console.WriteLine("Name - {0}", Name);
}
}
public class John : Student
{
public void DisplayInfo()
{
base.DisplayInfo("John");
Console.WriteLine("Class 9TH");
}
}
public class ID
{
public static void Main()
{
var myStudent = new John();
myStudent.DisplayInfo();
}
}

2- Contextual keywords:

Contextual Keywords are not like reserved keywords. These keywords convey special meaning in relevant parts of the code. The contextual keywords can be used as valid identifiers.

Given below is the list of Contextual Keywords:

addintoasynclet dynamic
fromgetdescending ascendingorderby
groupaliasglobal awaitnameof
joinpartialsetremovevar
valueselectwhenWhereyield
using System;
public class Student
{
public static void Main()
{
int await = 36;
Console.WriteLine(await);
}
}