位/字节转换

Jam*_*ead 2 .net c# byte bit

多少位是一个长度为10个字符的.NET字符串?(.NET字符串是UTF-16,对吧?)

Fra*_*ger 7

在32位系统上:

4 bytes          = Type pointer (Every object has one of these)
4 bytes          = Lock         (One of these too!)
4 bytes          = Length       (Need the length)
2 * Length bytes = Data         (And the chars themselves)
=======================
12 + 2*Length bytes
=======================
96 + 16*Length bits
Run Code Online (Sandbox Code Playgroud)

所以10个字符= 256位 = 32个字节

我不确定在64位系统上Lock是否会增长到64位.我有点希望,但你永远不会知道.因此,64位结构开销是16-20字节(而不是32位的12字节).