Preface
If you need to process many bits, you can use the bitarray class and bitvector32 structure. Bitarray is located in the namespace system. collections, and bitvector32 is located in the namespace system. Collections. Specialized.
I. bitarrayClassReference Type
The bitarray class is a reference type and contains an int array. Each 32 bits use a new integer.
My understanding: bitarray is equivalent to a bool array bool []
Official explanation: the bitarray class is a reference type that contains an int array. Every 32 bits use a new integer.
Eg
Other methods: and (), or (), XOR (), get ()
Eg
Ii. bitvector32 structure Value Type
If you know the required digits in advance, you can use the bitvector32 structure to replace bitarray. Bitvector32 is more efficient because it is a value type and stores bits on the integer stack. An integer can store 32 bits. * ['Vekt finished] n. vector; carrier; route vt. use radio navigation
Eg
In addition to using the createmask () method to create a mask, you can also define the mask yourself or set multiple digits at a time. The octal 010 is the same as the binary value 1010. It can be expressed in this way
Bits1 [010] = true;
Differences
The most important difference between the two types is that bitarray can reset the size. If you do not know the number of digits, you can use bitarray, which can contain many digits. Bitvector32 is stack-based, so it is faster. Bitvector32 contains only 32 bits and is stored in an integer.