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 −

abstract As base bool break byte case
catch Char checked class const continue decimal
default delegate do double else enum event
explicit Extern false finally fixed float for
foreach Goto if implicit in in (generic modifier) int
interface internal is lock long namespace new
null Object operator out out (generic modifier) override params
private protected public readonly ref return sbyte
sealed Short sizeof stackalloc static string struct
switch This throw true try typeof uint
ulong unchecked unsafe ushort using virtual void
volatile While

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
Updated on: 2020-06-20T10:25:34+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements