为什么Marshal.SizeOf()把struct的大小凑成了偶数?
struct定义如下
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
internal struct DllInvoices
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
public byte[] serial;
public byte Type;
public uint Sum;
}
调用Marshal.Size得到的大小为9
添加一个字段Sum:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
internal struct DllInvoices
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
public byte[] serial;
public byte Type;
public uint Sum;
}
调用Marshal.Size得到的大小为16,为什么不是13?