Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Copying BitArray elements to an Array in C#
To copy BitArray elements to an Array, the code is as follows −
Example
using System;
using System.Collections;
public class Demo {
public static void Main(){
BitArray arr = new BitArray(2);
arr[0] = false;
arr[1] = true;
Console.WriteLine("Elements in BitArray...");
foreach (bool res in arr){
Console.WriteLine(res);
}
bool[] boolArr = new bool[2];
boolArr[0] = true;
boolArr[1] = false;
arr.CopyTo(boolArr, 0);
Console.WriteLine("
Array...");
foreach(Object obj in boolArr){
Console.WriteLine(obj);
}
}
}
Output
This will produce the following output −
Elements in BitArray... False True Array... False True
Example
Let us now see another example −
using System;
using System.Collections;
public class Demo {
public static void Main(){
BitArray arr = new BitArray(5);
arr[0] = false;
arr[1] = true;
arr[2] = false;
arr[3] = true;
arr[4] = true;
Console.WriteLine("Elements in BitArray...");
foreach (bool res in arr){
Console.WriteLine(res);
}
bool[] boolArr = new bool[10];
boolArr[0] = true;
boolArr[1] = false;
arr.CopyTo(boolArr, 0);
Console.WriteLine("
Array...");
foreach(Object obj in boolArr){
Console.WriteLine(obj);
}
}
}
Output
This will produce the following output −
Elements in BitArray... False True False True True Array... False True False True True False False False False False
Advertisements