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 Like