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). This class cannot be inherited.
public sealed class BitArray: Object, ICollection, IEnumerable, ICloneable
ObjectBitArray
// This examples shows how to create and initialize a BitArray.
// It shows also some properties and method of the BitArray class.
using System;
using System.Diagnostics;
using System.Collections;
public class SampleBitArray
{
static void Main()
{
// Creates and initialize different BitArrays.
bool[] myBools = new bool[6] {false, true, false, true, false, true};
);
BitArray myBA2 = new BitArray( 5, false );
bool[] myBools2 = new bool[5] { true, false, true, true, false };
BitArray myBA3 = new BitArray( myBools2 );
int[] myInts = new int[3] { 15, 25, 69 };
BitArray myBA4 = new BitArray( myInts );
bool[] myBools3 = new bool[5] { false, true, true, true, false };
BitArray myBA5 = new BitArray( myBools3 );
BitArray myBA6 = new BitArray((BitArray)myBA2);
BitArray myBA7 = new BitArray(6);
// Displays the contents of a BitArray.
Debug.Write("Contents of the BitArray 'myBA1':");
DisplayValues(myBA1);
Debug.Write("Contents of the BitArray 'myBA4':");
DisplayValues(myBA4);
Debug.Write("Contents of the BitArray 'myBA6':");
DisplayValues(myBA6);
Debug.Write("Contents of the BitArray 'myBA7':");
DisplayValues(myBA7);
// Length property.
Debug.WriteLine("\nLength of the BitArray 'myBA1':" +myBA1.Length);
// And Method.
Debug.Write("\nContents of the BitArray 'myBA3':");
DisplayValues(myBA3);
Debug.Write("\nContents of the BitArray 'myBA5':");
DisplayValues2(myBA5);
Debug.Write("\n\nResult of 'myBA3' AND 'myBA5':");
DisplayValues(myBA3);
// Clone Method.
object obj = (object)myBA1.Clone();
BitArray myBA8 = new BitArray((BitArray)obj);
Debug.Write("\n\nResults after cloning 'myBA1':");
DisplayValues(myBA8);
// Not Method.
Debug.Write("\n\nResults after using the NOT Method on 'myBA1':");
DisplayValues(myBA1);
// SetAll Method.
Debug.Write("\n\nContents of the BitArray 'myBA2':");
DisplayValues(myBA2);
Debug.Write("\nResults after using the SetAll 'true' Method on 'myBA2':");
DisplayValues2(myBA2);
// CopyTo Method.
Object[] myObjArray = new Object[5] { true, true, true, true, true };
Debug.Write("\n\nContents of an array of object:");
DisplayArrayValues(myObjArray);
Debug.Write("\nContents of the array after using the CopyTo Method on 'myBA3':");
DisplayArrayValues(myObjArray);
}
// Displays values of a BitArray.
public static void DisplayValues( BitArray myBitArray )
{
int count = myBitArray.Length;
for(int y=1; y<=count;y++)
{
Debug.Write(myBitArray.Get(y-1)+ " ");
}
}
// Displays values of a BitArray using an enumerator.
public static void DisplayValues2( BitArray myBitArray )
{
System.Collections.IEnumerator myEnumerator = myBitArray.GetEnumerator();
while(myEnumerator.MoveNext())
if (myEnumerator.Current!= null)
Debug.Write(myEnumerator.Current +" ");
}
// Display values of an array.
public static void DisplayArrayValues (Array myArray)
{
for(int y=1; y<=myArray.Length;y++)
{
Debug.Write(myArray.GetValue(y-1)+ " ");
}
}
}
/*
The output of the sample.
Contents of the BitArray "myBA1":False True False True False True
Length of the BitArray "myBA1":6
Contents of the BitArray "myBA3":True False True True False
Contents of the BitArray "myBA5":False True True True False
Result of "myBA3" AND "myBA5":False False True True False
Results after cloning "myBA1":False True False True False True
Results after using the NOT Method on "myBA1":True False True False True False
Contents of the BitArray "myBA2":False False False False False
Results after using the SetAll "true" Method on "myBA2":True True True True True
Contents of an array of object:True True True True True
Contents of the array after using the CopyTo Method on "myBA3":False False True True False
*/
Namespace System.Collections Flash Library corlib.scl Flash Library Version 2.0.0.2466 Silverlight Library System.Windows.Forms.dll
| © 2003-2007 NETiKA Technologies. All rights reserved. |