Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Index-based I/O BitArray collection trong C#


BitArray quản lý mảng bit compact, biểu diễn bằng Boolean: true=1 (on), false=0 (off).

Các phương thức chính:

Sr.No.Phương thức & Mô tả
1And(BitArray) - Bitwise AND với BitArray khác.
2Get(int index) - Lấy giá trị bit tại vị trí.
3Not() - Đảo ngược tất cả bit.
4Or(BitArray) - Bitwise OR.
5Set(int index, bool value) - Set bit tại vị trí.
6SetAll(bool value) - Set tất cả bit.
7Xor(BitArray) - Bitwise XOR.

Ví dụ

using System;
using System.Collections;
public class Demo {
    public static void Main() {
        BitArray arr = new BitArray(10);
        Console.WriteLine("Count: {0}", arr.Count);
    }
}