How to create a shallow copy of BitArray in C# Last Updated : 07 Feb, 2019 Comments Improve Suggest changes Like Article Like Report BitArray.Clone() Method is used to create a shallow copy of the specified BitArray. A shallow copy of a collection copies only the elements of the collection irrespective of reference types or value types. But it does not copy the objects that the references refer to. The references in the new collection point to the same objects that the references in the original collection point to. Syntax: public object Clone (); Example: csharp // C# code to illustrate the use // of BitArray.Clone Method using System; using System.Collections; public class GFG { // Main Method public static void Main(String[] args) { // Creating an empty BitArray BitArray bit1 = new BitArray(4); // Initializing values in bit1 bit1[0] = false; bit1[1] = false; bit1[2] = true; bit1[3] = true; // Displaying the list Console.WriteLine("Elements of Original BitArray: \n"); // calling function Result(bit1); // using Clone() method BitArray bit2 = (BitArray)bit1.Clone(); // Displaying the Cloned BitArray Console.WriteLine("\nElements of Cloned BitArray: \n"); // calling function Result(bit2); // checking for the equality // of References bit1 and bit2 Console.WriteLine("\nReference Equals: {0}", Object.ReferenceEquals(bit1, bit2)); } // method to display the values public static void Result(IEnumerable bit) { // This method prints all the // elements in the BitArray. foreach(Object obj in bit) Console.WriteLine(obj); } } Output: Elements of Original BitArray: False False True True Elements of Cloned BitArray: False False True True Reference Equals: False Comment More infoAdvertise with us Next Article How to create a shallow copy of BitArray in C# K Kirti_Mangal Follow Improve Article Tags : C# CSharp-method CSharp-Collections-Namespace CSharp-Collections-BitArray Similar Reads C# | How to create a shallow copy of the BitArray 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.Syntax: public object Clone (); Example 1: Here we create an 3 min read How to create a shallow copy of ArrayList in C# ArrayList.Clone() Method is used to create a shallow copy of the specified ArrayList. A shallow copy of a collection copies only the elements of the collection irrespective of reference types or value types. But it does not copy the objects that the references refer to. The references in the new col 3 min read How to create a shallow copy of Hashtable in C# Hashtable.Clone Method is used to create a shallow copy of the Hashtable. When we make a shallow copy, only the elements of the collection get copied irrespective of its type, it doesn't copy the objects referred to by the references. Basically, it creates a new object and that object points to the 3 min read How to create a shallow copy of SortedList Object in C# SortedList.Clone() Method is used to create a shallow copy of a SortedList object. Syntax: public virtual object Clone(); Return Value: It returns a shallow copy of the SortedList object. The type of returned value will be Object. Note: A shallow copy of a collection copies only the elements of the 3 min read Shallow Copy and Deep Copy in C# In general, when we try to copy one object to another object, both the objects will share the same memory address. Normally, we use assignment operator, = , to copy the reference, not the object except when there is value type field. This operator will always copy the reference, not the actual objec 5 min read C# | Copying BitArray elements to an Array The BitArray class manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on i.e, 1 and false indicates the bit is off i.e, 0. This class is contained in System.Collections namespace. BitArray.CopyTo(Array, Int32) method is used to copy the ent 3 min read How to Combine Two Arrays without Duplicate values in C#? Given two arrays, now our task is to merge or combine these arrays into a single array without duplicate values. So we can do this task using the Union() method. This method combines two arrays by removing duplicated elements in both arrays. If two same elements are there in an array, then it will t 3 min read C# | How to copy the entire ArrayList to a one-dimensional Array ArrayList.CopyTo Method is used to copy the entire ArrayList to a compatible one-dimensional Array, starting at the beginning of the target array. Syntax: public virtual void CopyTo (Array array); Here, array is the one-dimensional Array which is the destination of the elements copied from ArrayList 3 min read C# | Check if two BitArray objects are equal Equals(Object) Method which is inherited from the Object class is used to check if a specified BitArray object is equal to another BitArray object or not. Syntax: public virtual bool Equals (object obj); Here, obj is the object which is to be compared with the current object. Return Value: This meth 2 min read C# | Copy the entire LinkedList<T> to Array LinkedList<T>.CopyTo(T[], Int32) method is used to copy the entire LinkedList<T> to a compatible one-dimensional Array, starting at the specified index of the target array. Syntax: public void CopyTo (T[] array, int index); Parameters: array : It is the one-dimensional Array that is the 2 min read Like