CSharp - Collection BitArray Type

Introduction

A BitArray is a dynamically sized collection of compacted bool values.

BitArray's indexer reads and writes individual bits:

var bits = new BitArray(2);
bits[1] = true;

There are four bitwise operator methods (And, Or, Xor, and Not).

All but the last accept another BitArray:

bits.Xor (bits);               // Bitwise exclusive-OR bits with itself
Console.WriteLine (bits[1]);   // False

Demo

using System;
using System.Collections;
class MainClass/* ww w  .j a v  a  2  s. c o m*/
{
    public static void Main(string[] args)
    {
        var bits = new BitArray(2);
        bits[1] = true;
        Console.WriteLine(bits);
        Console.WriteLine(bits[0]);
        Console.WriteLine(bits[1]);

    }
}

Result