What are reserved keywords in C#?

CsharpProgrammingServer Side Programming

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
raja
Published on 06-Aug-2018 11:39:14
Advertisements