C# BitArray Set

Description

BitArray Set sets the bit at a specific position in the BitArray to the specified value.

Syntax

BitArray.Set has the following syntax.


public void Set(
  int index,
  bool value
)

Parameters

BitArray.Set has the following parameters.

  • index - The zero-based index of the bit to set.
  • value - The Boolean value to assign to the bit.

Returns

BitArray.Set method returns

Example

The following code example shows how to set and get specific elements in a BitArray.


//from ww w. j a  va  2  s.c  o  m
using System;
using System.Collections;
public class SamplesBitArray  {

   public static void Main()  {
      BitArray myBA = new BitArray( 5 );
      myBA.Set( myBA.Count - 1, false );

      PrintIndexAndValues( myBA );
   }


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

}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack