Why is a boolean 4 bytes in .NET?

前端 未结 6 2229
我在风中等你
我在风中等你 2020-11-29 07:54

Why does a System.Boolean take 4 bytes? It just stores one state, either true or false, which could be stored in less space than 4 bytes.

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 08:38

    The first result on a Google search for System.Boolean size told me that it's to do with memory alignment. It's faster to push around a four-byte Int32 than it is to work with individual bytes/bits.

提交回复
热议问题