
- 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
How to create a shallow copy of the BitArray in C#?
To create a shallow copy of the BitArray, the code is as follows −
Example
using System; using System.Collections; public class Demo { public static void Main(){ BitArray arr1 = new BitArray(5); arr1[0] = false; arr1[1] = true; Console.WriteLine("BitArray length = "+arr1.Length); Console.WriteLine("BitArray first element = "+arr1.Get(0)); Console.WriteLine("BitArray second element = "+arr1.Get(1)); BitArray arr2 = (BitArray)arr1.Clone(); Console.WriteLine("
BitArray2 length = "+arr2.Length); Console.WriteLine("BitArray2 first element = "+arr2.Get(0)); Console.WriteLine("BitArray2 second element = "+arr2.Get(1)); } }
Output
This will produce the following output −
BitArray length = 5 BitArray first element = False BitArray second element = True BitArray2 length = 5 BitArray2 first element = False BitArray2 second element = Tru
Example
Let us now see another example −
using System; using System.Collections; public class Demo { public static void Main(){ BitArray arr1 = new BitArray(5); arr1[0] = false; arr1[1] = true; arr1[2] = false; arr1[3] = true; arr1[3] = true; Console.WriteLine("BitArray length = "+arr1.Length); Console.WriteLine("Elements in BitArray1..."); foreach(Object obj in arr1) Console.WriteLine(obj); BitArray arr2 = (BitArray)arr1.Clone(); Console.WriteLine("
BitArray2 length = "+arr1.Length); Console.WriteLine("Elements in BitArray2..."); foreach(Object obj in arr2) Console.WriteLine(obj); } }
Output
This will produce the following output −
BitArray length = 5 Elements in BitArray1... False True False True False BitArray2 length = 5 Elements in BitArray2... False True False True False
- Related Articles
- How to create a shallow copy of Hashtable in C#?
- How to create a shallow copy of ArrayList in C#?
- How to create a shallow copy of SortedList Object in C#?
- How to shallow copy the objects in JavaScript?
- Deep Copy and Shallow Copy in Java
- Return a shallow copy of IdentityHashMap in Java
- What is Shallow Copy and how it is different from Deep Copy in C#?
- Copy - Shallow and deep copy operations in Python
- How do you make a shallow copy of a list in Java?
- What is the difference between shallow copy and deep copy in Java?
- Python Shallow and Deep Copy operations
- How to create a copy of an object in PHP?
- What is shallow copy? Explain with an example in Java.
- BitArray Class in C#
- How to flatten a shallow list in Python?

Advertisements