要检查两个BitArray对象是否相等,代码如下-
using System; using System.Collections; public class Demo { public static void Main(){ BitArray arr1 = new BitArray(2); BitArray arr2 = new BitArray(2); arr1[0] = false; arr1[1] = true; Console.WriteLine("Elements in BitArray1..."); foreach (bool res in arr1){ Console.WriteLine(res); } arr2[0] = false; arr2[1] = true; Console.WriteLine("Elements in BitArray2..."); foreach (bool res in arr2){ Console.WriteLine(res); } BitArray arr3 = new BitArray(2); arr3 = arr2; Console.WriteLine("Is BitArry2 equal to BitArray3? = "+arr2.Equals(arr3)); } }
输出结果
这将产生以下输出-
Elements in BitArray1... False True Elements in BitArray2... False True Is BitArry2 equal to BitArray3? = True
让我们看另一个例子-
using System; using System.Collections; public class Demo { public static void Main(){ BitArray arr1 = new BitArray(2); BitArray arr2 = new BitArray(2); arr1[0] = false; arr1[1] = true; Console.WriteLine("Elements in BitArray1..."); foreach (bool res in arr1){ Console.WriteLine(res); } arr2[0] = false; arr2[1] = true; Console.WriteLine("Elements in BitArray2..."); foreach (bool res in arr2){ Console.WriteLine(res); } Console.WriteLine("Is BitArry1 equal to BitArray2? = "+arr1.Equals(arr2)); } }
输出结果
这将产生以下输出-
Elements in BitArray1... False True Elements in BitArray2... False True Is BitArry1 equal to BitArray2? = False