Shimmy Weitzhandler
Shimmy Weitzhandler

Reputation: 104791

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

How about a Nibble etc.

Upvotes: 8

Views: 5336

Answers (3)

Mandelbrot
Mandelbrot

Reputation: 512

No, byte is the smallest.

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

Upvotes: 1

LBushkin
LBushkin

Reputation: 131806

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.

Upvotes: 5

Jon Skeet
Jon Skeet

Reputation: 1503090

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.

Upvotes: 16

Related Questions