G
Guest
Hi all,
I have several question about BitArray and BitVector32.
--------------------------------------------
1. Counting 'true' from BitArray items
--------------------------------------------
BitArray keys = new BitArray(32);
....
int a = 0;
for (int i = 0; i < keys.Count; i++)
a += (keys) ? 1 : 0;
Should I apply loop like above?
----------------------------------------------------------------
2. The difference between Length and Count of BitArray
----------------------------------------------------------------
According to the MSDN:
Count - Gets the number of elements contained in the BitArray.
Length - Gets or sets the number of elements in the BitArray.
As we know, BitArray can expand or contract by changing Length: however, why
does this provide a readonly property, 'Count'? Are they different?
-----------------------------------------------------------------
3. Why doesn't BitVector32 implement bitwise operation?
-----------------------------------------------------------------
According to the MSDN:
'BitVector32 is more efficient than BitArray for Boolean values and small
integers that are used internally. A BitArray can grow indefinitely as
needed, but it has the memory and performance overhead that a class instance
requires. In contrast, a BitVector32 uses only 32 bits.'
Yes, that's cool. But Why no bitwise op. Instead, why does it have Mask and
Section? And why BitArray does not implement such cool Mask and Section?
I have several question about BitArray and BitVector32.
--------------------------------------------
1. Counting 'true' from BitArray items
--------------------------------------------
BitArray keys = new BitArray(32);
....
int a = 0;
for (int i = 0; i < keys.Count; i++)
a += (keys) ? 1 : 0;
Should I apply loop like above?
----------------------------------------------------------------
2. The difference between Length and Count of BitArray
----------------------------------------------------------------
According to the MSDN:
Count - Gets the number of elements contained in the BitArray.
Length - Gets or sets the number of elements in the BitArray.
As we know, BitArray can expand or contract by changing Length: however, why
does this provide a readonly property, 'Count'? Are they different?
-----------------------------------------------------------------
3. Why doesn't BitVector32 implement bitwise operation?
-----------------------------------------------------------------
According to the MSDN:
'BitVector32 is more efficient than BitArray for Boolean values and small
integers that are used internally. A BitArray can grow indefinitely as
needed, but it has the memory and performance overhead that a class instance
requires. In contrast, a BitVector32 uses only 32 bits.'
Yes, that's cool. But Why no bitwise op. Instead, why does it have Mask and
Section? And why BitArray does not implement such cool Mask and Section?