What is the Item property of BitArray class in C#?


The Item property of the BitArray class gets or sets the value of the bit at a specific position in the BitArray.

Use the keyword to define the indexers instead of implementing the Item property. To access an element, use the mycollection[index].

The following is the implementation of BitArray class Item property −

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

48 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements