What is index-based I/O BitArray collection in C#?


The BitArray class manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on (1) and false indicates the bit is off (0).

The following are the method of the index-based BitArray collection −

Sr.No.Method & Description
1public BitArray And(BitArray value);
Performs the bitwise AND operation on the elements in the current BitArray against the corresponding elements in the specified BitArray.
2public bool Get(int index);
Gets the value of the bit at a specific position in the BitArray.
3public BitArray Not();
Inverts all the bit values in the current BitArray, so that elements set to true are changed to false, and elements set to false are changed to true.
4public BitArray Or(BitArray value);
Performs the bitwise OR operation on the elements in the current BitArray against the corresponding elements in the specified BitArray.
5public void Set(int index, bool value);
Sets the bit at a specific position in the BitArray to the specified value.
6public void SetAll(bool value);
Sets all bits in the BitArray to the specified value.
7public BitArray Xor(BitArray value);
Performs the bitwise eXclusive OR operation on the elements in the current BitArray against the corresponding elements in the specified BitArray.

The following is an example −

using System;
using System.Collections;

public class Demo {

   public static void Main() {

      BitArray arr = new BitArray(10);

      Console.WriteLine( "Count: {0}", arr.Count );
   }
}

Updated on: 21-Jun-2020

96 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements