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

依然范特西╮ 提交于 2019-12-06 00:40:34

问题


How about a Nibble etc.


回答1:


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.




回答2:


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:


No, byte is the smallest.

This may be helpful: How can you nibble (nybble) bytes in C#?



来源:https://stackoverflow.com/questions/3213630/is-there-a-net-data-type-smaller-than-a-byte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!