Why isn't the size of a bool data type only 1 bit in C#?

user1063287 picture user1063287 · Jul 19, 2013 · Viewed 11.7k times · Source

I am just learning C# and looking deeper into data types.

Why isn't a bool data type 1 bit in size?

It seems it can only hold one of two values (true or false), so wouldn't that only take up 1 bit of space to represent that value?

Is it because the smallest 'addressable' size of a value is a byte (8 bits) as referred to in this post?

My overall aim was to logically envisage the different size of each data type in C# so I was trying to create a list of all data types and their allocated bit size and this threw me.

Answer

SteveLove picture SteveLove · Jul 19, 2013

Is it because the smallest 'addressable' size of a value is a byte

Yep, exactly the same thing. In order for the CLR to be efficient, it maps its data types to the native machine data types in much the same way as the compiler does in C++ (pretty much).