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.
There's no native data-type smaller than byte, however if you want to store and manipulate a group of packed bits, you can use BitVector32 or BitArray.
发布评论
评论(3)
不。即使您有一个布尔数组,我相信它们也被指定为每个布尔数组占用一个字节。
当然,您可以定义自己的数据类型,其有效值少于 256 个(如
Boolean
那样),但您不能使其在内存中占用的空间少于一个字节。正如 LBushkin 指出的那样,诸如
BitArray
和BitVector32
之类的类型可以有效地高效打包多个位 - 如果您愿意,您可以编写自己的NybbleArray
类型通缉。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
andBitVector32
which effectively pack multiple bits efficiently - you could write your ownNybbleArray
type if you wanted.没有比字节更小的本机数据类型,但是如果您想存储和操作一组打包位,可以使用 BitVector32 或 位数组。
There's no native data-type smaller than byte, however if you want to store and manipulate a group of packed bits, you can use BitVector32 or BitArray.
不,字节是最小的。
这可能会有所帮助:How can you nibble (nybble) bytes in C#?
No, byte is the smallest.
This may be helpful: How can you nibble (nybble) bytes in C#?