BitArray.Clone Method is used to create a shallow copy of the BitArray. This method only copies the elements of the collection, whether they are reference types or value types, but it does not copy the objects that the references refer to.
public object Clone ();
Example 1: Here we create an array of type byte. Then declare an object B1 of type BitArray and initialize it using the byte array created before. Declare another object B2 of type BitArray which will be used to store the clone of B1. The instruction B1.Clone returns the shallow copy of B1, which is of type System.Collections. Therefore explicity convert it to BitArray before storing it in B2 object. And finally, display the cloned BitArray.
Length of B2: 16 B2 Contains: True False False False False False False False True True False False False False False False
Example 2: A shallow copy only copies the contents of the BitArray and not the object references, any changes made to B2 will only update those changes in B2 and not in B1.
B2 Before Making any changes: True False True False B2 After changes: False True True False B1 After Changes: True False True False
- How to create a shallow copy of BitArray in C#
- How to create a shallow copy of ArrayList in C#
- How to create a shallow copy of Hashtable in C#
- How to create a shallow copy of SortedList Object in C#
- Shallow Copy and Deep Copy in C#
- How to create a copy of an object in PHP?
- C# | Set all bits in the BitArray to the specified value
- C# | BitArray Class
- C# | Set the bit at a specific position in the BitArray to the specified value
- C# | Get or set the number of elements in the BitArray
- C# | Inverting all bit values in BitArray
- C# | Bitwise AND between the elements of BitArray
- C# | Enumerator that iterates through the BitArray
- C# | Get value of the bit at a specific position in BitArray
- C# | Check if the BitArray is read-only
- C# | Number of elements contained in the BitArray
- C# | Copying BitArray elements to an Array
- C# | Check if two BitArray objects are equal
- C# | Gets or sets the value of the bit at a specific position in the BitArray
- C# | Bitwise OR operation between the elements of BitArray
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.