gpt4 book ai didi

c# - 显示错误输出的结构的 Marshal.SizeOf

转载 作者:行者123 更新时间:2023-11-30 20:16:18 25 4
gpt4 key购买 nike

<分区>

这是我的代码:

struct abc
{
short a;
byte b;
int c;
}

当我使用时:

Console.WriteLine(System.Runtime.InteropServices.Marshal.SizeOf(typeof(abc)));

它显示:8 而它应该显示:7 因为在我的机器中:byte: 1, short:2, int:4 字节。

为什么会这样?

如果它是由于填充而发生的,如何在读取结构大小时禁用填充?因为我需要以字节为单位的结构的确切大小。这很重要。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com