neuromouse
neuromouse

Reputation: 941

Can BitArray be dynamic? Or is List<bool> the only way?

Taking a look at BitArray's methods, I could not see any method to add a new boolean to the array - so is the size of BitArray static? I am using a lot (millions, maybe tens of millions) of bits so would really love the advantage of BitArray using only 1/8th of space of boolean array - however, I need it to be dynamic. Is the use of List<bool> my only way to use the dynamic length? Or perhaps List<byte> and bitwise operations on that - is there some way around that?

Upvotes: 2

Views: 2870

Answers (1)

Yuriy Faktorovich
Yuriy Faktorovich

Reputation: 68667

You can create a wrapper class around it which implements IList<bool>, but uses a BitArray to store the data. Remember, you can resize a BitArray using the Length property.

Upvotes: 8

Related Questions