Q:

C# program to copy the entire BitArray to a compatible one-dimensional Array (BitArray.CopyTo() Method)

belongs to collection: C# BitArray Class Programs

0

Syntax:

    void BitArray.CopyTo(Array array, int arrayIndex);

Parameter(s):

  • array: An array to copy elements of BitArray.
  • index: The index in array at which copying begins.

Return value:

It does not return any value.

Exception(s):

  • System.ArgumentNullException
  • System.ArgumentOutOfRangeException
  • System.ArgumentException
  • System.InvalidCastException
  •  

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to copy the entire BitArray to a compatible one-dimensional Array is given below. The given program is compiled and executed successfully.

using System;
using System.Collections;

class BitArrayEx
{
    //Entry point of Program
    static public void Main()
    {
        //Creation of BitArray objects
        BitArray bitArr1 = new BitArray(5);
        bool[]  Arr = new bool[8];
        int index = 0;

        bitArr1[0] = true;
        bitArr1[1] = false;
        bitArr1[2] = true;
        bitArr1[3] = false;
        bitArr1[4] = true;

        bitArr1.CopyTo(Arr, 0);

        Console.WriteLine("Elements of BitArray1:");
        for (index = 0; index < bitArr1.Length; index++)
        {
            Console.WriteLine("\tIndex " + index + ": " + bitArr1.Get(index));
        }

        Console.WriteLine("Array Values:");
        for (index = 0; index < Arr.Length; index++)
        {
            Console.WriteLine("\t"+Arr[index]);
        }
    }
}

Output:

Elements of BitArray1:
        Index 0: True 
        Index 1: False
        Index 2: True
        Index 3: False
        Index 4: True
Array Values:
        True
        False
        True
        False
        True
        False
        False
        False
Press any key to continue . . .

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# program to create a shallow copy of the BitArra... >>
<< C# program to get or set the number of elements in...