Mega Code Archive

 
Categories / C# / Collections Data Structure
 

Gets the value of the bit at a specific position in the BitArray

using System; using System.Collections; public class SamplesBitArray  {    public static void Main()  {       BitArray myBA = new BitArray( 5 );       myBA.SetAll( true );       PrintIndexAndValues( myBA );       myBA.Set( myBA.Count - 1, false );       PrintIndexAndValues( myBA );       Console.WriteLine( myBA.Get( myBA.Count - 2 ) );       Console.WriteLine( myBA.Get( myBA.Count - 1 ) );    }    public static void PrintIndexAndValues( IEnumerable myCol )  {       int i = 0;       foreach ( Object obj in myCol ) {          Console.WriteLine( "    [{0}]:    {1}", i++, obj );       }    } }