是否有一个.NET数据类型不是一个字节的小?字节、数据类型、有一个、不是

2023-09-03 23:04:00 作者:独步杀戮

怎么样蚕食等。

推荐答案

没有。即使你有布尔数组,我相信他们指定的占用每一个字节。

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

当然,你可以定义哪些少于256有效值(如布尔一样)自己的数据类型,但你不能让它占用不到一个字节在存储器中。

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.

由于LBushkin指出,有型,如 BitArray BitVector32 ,有效地高效地打包多个位 - 你可以编写自己的 NybbleArray 如果你想要的类型。

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.