C# BitArray BitArray(Int32, Boolean)

Description

BitArray BitArray(Int32, Boolean) initializes a new instance of the BitArray class that can hold the specified number of bit values, which are initially set to the specified value.

Syntax

BitArray.BitArray(Int32, Boolean) has the following syntax.


public BitArray(
  int length,
  bool defaultValue
)

Parameters

BitArray.BitArray(Int32, Boolean) has the following parameters.

  • length - The number of bit values in the new BitArray.
  • defaultValue - The Boolean value to assign to each bit.

Example


using System;/*  w  ww.  jav a  2  s.c om*/
using System.Collections;
public class SamplesBitArray  {
   public static void Main()  {
      BitArray myBA = new BitArray( 4,false);
      myBA[0] = myBA[1] = myBA[2] = myBA[3] = true;

      bool[] myBoolArray = new bool[8];
      myBoolArray[0] = false;
      myBoolArray[1] = false;

      myBA.CopyTo( myBoolArray, 3 );
   }

   public static void PrintValues( IEnumerable myArr )  {
      foreach ( Object obj in myArr ) {
         Console.WriteLine(obj );
      }
   }
}




















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack