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
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