
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- Copying the Collection elements to an array in C#
- Copying the Hashtable elements to an Array Instance in C#
- Copying the SortedList elements to an Array Object in C#
- Copying the Queue elements to one-dimensional array in C#
- Copying the elements of ArrayList to a new array in C#
- Copying the HybridDictionary entries to an Array Instance in C#
- Number of elements contained in the BitArray in C#?
- Bitwise OR operation between the elements of BitArray in C#
- Bitwise exclusive OR operation between the elements of BitArray in C#
- How to initialize elements in an array in C#?
- Get or set the number of elements in the BitArray in C#
- C program to reverse an array elements
- BitArray Class in C#
- How to access elements from an array in C#?
- C# Program to skip initial elements in an array

Advertisements