获取或设置C#中BitArray中的元素数
要获取或设置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("BitArray1 length = "+arr1.Length);
Console.WriteLine("Elements in BitArray1...");
foreach (bool res in arr1) {
Console.WriteLine(res);
}
arr2[0] = false;
arr2[1] = true;
Console.WriteLine("\nBitArray2 length = "+arr2.Length);
Console.WriteLine("Elements in BitArray2...");
foreach (bool res in arr2) {
Console.WriteLine(res);
}
Console.WriteLine("\nIs BitArray1 equal to BitArray2? = "+arr2.Equals(arr1));
}
}输出结果
这将产生以下输出-
BitArray1 length = 2 Elements in BitArray1... False True BitArray2 length = 2 Elements in BitArray2... False True Is BitArray1 equal to BitArray2? = False
示例
让我们看另一个例子-
using System;
using System.Collections;
public class Demo {
public static void Main() {
BitArray arr1 = new BitArray(2);
BitArray arr2 = new BitArray(1);
arr1[0] = false;
arr1[1] = true;
Console.WriteLine("BitArray1 length = "+arr1.Length);
Console.WriteLine("Elements in BitArray1...");
foreach (bool res in arr1) {
Console.WriteLine(res);
}
Console.WriteLine("\nBitArray2 length = "+arr2.Length);
Console.WriteLine("Elements in BitArray2...");
foreach (bool res in arr2) {
Console.WriteLine(res);
}
}
}输出结果
这将产生以下输出-
BitArray1 length = 2 Elements in BitArray1... False True BitArray2 length = 1 Elements in BitArray2... False
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短