为什么C#中bool数据类型的大小不是只有1位? [英] Why isn't the size of a bool data type only 1 bit in C#?

查看:212
本文介绍了为什么C#中bool数据类型的大小不是只有1位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习C#,并更深入地研究数据类型.

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

为什么bool数据类型的大小不是1位?

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

似乎它只能容纳两个值(对或错)之一,所以岂不是只占用1位空间来表示该值吗?

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?

是因为值的最小可寻址"大小是一个字节(8位),如这篇文章中所述?

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

我的总体目标是在逻辑上设想C#中每种数据类型的不同大小,因此我试图创建所有数据类型及其分配的位大小的列表,这使我感到震惊.

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.

推荐答案

是因为值的最小可寻址"大小是一个字节

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

是的,完全一样.为了使CLR高效,它以与C ++中的编译器相同的方式(非常多)将其数据类型映射到本机数据类型.

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).

这篇关于为什么C#中bool数据类型的大小不是只有1位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆