Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a .NET data-type smaller than a byte?

How about a Nibble etc.

like image 716
Shimmy Weitzhandler Avatar asked Jul 09 '10 14:07

Shimmy Weitzhandler


1 Answers

No. Even if you have an array of Booleans, I believe they're specified to take up one byte each.

Of course you can define your own data types which have fewer than 256 valid values (like Boolean does) but you can't make it take up less than a byte in memory.

As LBushkin pointed out, there are types such as BitArray and BitVector32 which effectively pack multiple bits efficiently - you could write your own NybbleArray type if you wanted.

like image 176
Jon Skeet Avatar answered Sep 27 '22 22:09

Jon Skeet