Prev: Using Delegates?
Next: Drag & Drop text
From: keeling on 16 Jun 2010 08:31 I am surprised that no one pointed out that .NET has a way of treating Boolean values as bits. Its called... a BitArray (http:// msdn.microsoft.com/en-us/library/system.collections.bitarray.aspx). If you are concerned with the memory you are using to store Boolean values (e.g. you have a large collection of them) this may be a solution for you. As for why a bool is 4 bytes; my understanding was that it is more efficient. :-)
From: Rudy Velthuis on 16 Jun 2010 18:10
keeling wrote: > I am surprised that no one pointed out that .NET has a way of treating > Boolean values as bits. Its called... a BitArray (http:// > msdn.microsoft.com/en-us/library/system.collections.bitarray.aspx). Well yes, I guess many platforms have such a class. But it requires bit shifting, etc. Booleans are best stored as single bytes. BitArrays are useful if you have to store many, many booleans and access time is not too critical. -- Rudy Velthuis http://rvelthuis.de "Think my friends! You adulate a stone as Vishnu but you cannot see God in a fellow man." -- Sankaracharya |