BitArray की एक उथली प्रतिलिपि बनाने के लिए, कोड इस प्रकार है -
उदाहरण
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("\nBitArray2 length = "+arr2.Length); Console.WriteLine("BitArray2 first element = "+arr2.Get(0)); Console.WriteLine("BitArray2 second element = "+arr2.Get(1)); } }
आउटपुट
यह निम्नलिखित आउटपुट देगा -
BitArray length = 5 BitArray first element = False BitArray second element = True BitArray2 length = 5 BitArray2 first element = False BitArray2 second element = Tru
उदाहरण
आइए अब एक और उदाहरण देखें -
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("\nBitArray2 length = "+arr1.Length); Console.WriteLine("Elements in BitArray2..."); foreach(Object obj in arr2) Console.WriteLine(obj); } }
आउटपुट
यह निम्नलिखित आउटपुट देगा -
BitArray length = 5 Elements in BitArray1... False True False True False BitArray2 length = 5 Elements in BitArray2... False True False True False