illustrates the use of BitArray methods : BitArray « Collections Data Structure « C# / C Sharp






illustrates the use of BitArray methods

illustrates the use of BitArray methods
 
/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/

/*
  Example11_5.cs illustrates the use of BitArray methods
*/

using System;
using System.Collections;

public class Example11_5
{

  // the DisplayBitArray() method displays the elements in the
  // supplied BitArray
  public static void DisplayBitArray(
    string arrayListName, BitArray myBitArray
  )
  {
    for (int counter = 0; counter < myBitArray.Count; counter++)
    {
      Console.WriteLine(arrayListName + "[" + counter + "] = " +
        myBitArray[counter]);
    }
  }

  public static void Main()
  {

    // create a BitArray object
    BitArray myBitArray = new BitArray(4);
    myBitArray[0] = false;
    myBitArray[1] = true;
    myBitArray[2] = true;
    myBitArray[3] = false;
    DisplayBitArray("myBitArray", myBitArray);

    // create another BitArray object, passing myBitArray to
    // the constructor
    BitArray anotherBitArray = new BitArray(myBitArray);
    DisplayBitArray("anotherBitArray", myBitArray);

    // use the Not() method to reverse the elements in myBitArray
    Console.WriteLine("Using the Not() method to reverse the element\n" +
      " values in myBitArray");
    myBitArray.Not();
    DisplayBitArray("myBitArray", myBitArray);

    // use the Or() method to perform an OR operation on the elements
    // in myBitArray and anotherBitArray
    Console.WriteLine("Using the Or() method to perform an OR operation on\n" +
      " the elements in myBitArray and anotherBitArray");
    myBitArray.Or(anotherBitArray);
    DisplayBitArray("myBitArray", myBitArray);

  }

}

           
         
  








Related examples in the same category

1.Demonstrate BitArrayDemonstrate BitArray
2.Use BitArray collection as Flag
3.illustrates the use of a BitArrayillustrates the use of a BitArray
4.BitArray Class manages a compact array of bit values
5.Displays the properties and values of the BitArrays
6.BitArray.CopyTo copies the entire BitArray to a compatible one-dimensional Array
7.Gets the value of the bit at a specific position in the BitArray.
8.Inverts all the bit values in the current BitArray
9.Performs the bitwise OR operation
10.Performing OR between BitArray instances of different sizes returns an exception
11.Performs bitwise exclusive OR operation