C# BitArray Not

Description

BitArray Not inverts all the bit values in the current BitArray, so that elements set to true are changed to false, and elements set to false are changed to true.

Syntax

BitArray.Not has the following syntax.


public BitArray Not()

Returns

BitArray.Not method returns The current instance with inverted bit values.

Example

The following code example shows how to apply NOT to a BitArray.


// w  w  w.  j a  va 2s.c  om
using System;
using System.Collections;
public class SamplesBitArray  {

   public static void Main()  {
      BitArray myBA1 = new BitArray( 4 );
      BitArray myBA2 = new BitArray( 4 );
      myBA1[0] = myBA1[1] = false;
      myBA1[2] = myBA1[3] = true;
      myBA2[0] = myBA2[2] = false;
      myBA2[1] = myBA2[3] = true;

      myBA1.Not();
      myBA2.Not();

      PrintValues( myBA1);
      PrintValues( myBA2);
   }


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

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack