What are reserved keywords in C#?


Keywords are reserved words predefined to the C# compiler. These keywords cannot be used as identifiers. If you want to use these keywords as identifiers, you may prefix the keyword with the @ character.

In C#, some identifiers have special meaning in the context of code, such as get and set are called contextual keywords.

The following table lists the reserved keywords −

abstractAsbaseboolbreakbytecase
catchCharcheckedclassconstcontinuedecimal
defaultdelegatedodoubleelseenumevent
explicitExternfalsefinallyfixedfloatfor
foreachGotoifimplicitinin (generic modifier)int
interfaceinternalislocklongnamespacenew
nullObjectoperatoroutout (generic modifier)overrideparams
privateprotectedpublicreadonlyrefreturnsbyte
sealedShortsizeofstackallocstaticstringstruct
switchThisthrowtruetrytypeofuint
ulonguncheckedunsafeushortusingvirtualvoid
volatileWhile

Let us see an example of using bool reserved keyword in C# −

Example

 Live Demo

using System;
using System.Collections;

class Demo {
   static void Main() {
      bool[] arr = new bool[5];
      arr[0] = true;
      arr[1] = true;
      arr[2] = false;
      arr[3] = false;

      BitArray bArr = new BitArray(arr);

      foreach (bool b in bArr) {
         Console.WriteLine(b);
      }

      bool str = arr[1];
      Console.WriteLine("Value of 2nd element:"+str);
   }
}

Output

True
True
False
False
False
Value of 2nd element:True

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 20-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements