Bool Array in C#

CsharpProgrammingServer Side Programming

In a bool array, you can store true and false values. To set a bool array, use the new operator −

bool[] arr = new bool[5];

To add elements in the array −

arr[0] = true;
arr[1] = true;
arr[2] = false;
arr[3] = true;
arr[4] = true;

Let us see the complete code −

Example

 Live Demo

using System;

public class Demo {
   public static void Main() {
      bool[] arr = new bool[5];
      arr[0] = true;
      arr[1] = true;
      arr[2] = false;
      arr[3] = true;
      arr[4] = true;
      Console.WriteLine("Displaying values...");

      foreach (bool res in arr) {
         Console.WriteLine(res);
      }
   }
}

Output

Displaying values...
True
True
False
True
True
raja
Published on 04-Sep-2018 10:41:18
Advertisements