C# 中 BitArray 类的 Item 属性是什么?
csharpprogrammingserver side programming更新于 2025/10/14 21:52:17
BitArray 类的 Item 属性用于获取或设置 BitArray 中特定位置的位值。
使用关键字定义索引器,而不是实现 Item 属性。要访问元素,请使用 mycollection[index]。
以下是 BitArray 类 Item 属性的实现 −
示例
using System;
using System.Collections;
class Demo {
static void Main() {
bool[] arr = new bool[5];
arr[0] = true;
arr[1] = true;
arr[2] = false;
arr[3] = false;
BitArray bArr = new BitArray(arr);
foreach (bool b in bArr) {
Console.WriteLine(b);
}
bool str = arr[1];
Console.WriteLine("Value of 2nd element:"+str);
}
}
输出
True True False False False Value of 2nd element:True

