Delphi结构体:
TFileRec = packed Record
FileId: byte;
FileVar:byte;
RecCount: integer;
end;TTempPoleRec = packed Record
Id :word;
ParantId : word;
x : integer;
y : integer;
SubLine: array [0..49] of char;
PoleName: array [0..49] of char;
interval: byte;
DevCount: byte;
end;我转成C#的结构体如下:
[StructLayout(LayoutKind.Sequential)]
public struct FileStruct
{
public byte FileId;
public byte FileVar;
public Int32 RecCount;
} [StructLayout(LayoutKind.Sequential)]
public struct PoleRecord
{
public UInt16 Id;
public UInt16 ParentId;
public Int32 x;
public Int32 y;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)]
public byte[] SubLine;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)]
public byte[] PoleName;
public byte interval;
public byte DevCount;
}
可以理论上来说应该第一个是6字节,第二个结构体是114字节
可我用Marshal.SizeOf()算出来的第一个是8字节,第二个是116字节都多出来两字节
不知道为什么?
TFileRec = packed Record
FileId: byte;
FileVar:byte;
RecCount: integer;
end;TTempPoleRec = packed Record
Id :word;
ParantId : word;
x : integer;
y : integer;
SubLine: array [0..49] of char;
PoleName: array [0..49] of char;
interval: byte;
DevCount: byte;
end;我转成C#的结构体如下:
[StructLayout(LayoutKind.Sequential)]
public struct FileStruct
{
public byte FileId;
public byte FileVar;
public Int32 RecCount;
} [StructLayout(LayoutKind.Sequential)]
public struct PoleRecord
{
public UInt16 Id;
public UInt16 ParentId;
public Int32 x;
public Int32 y;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)]
public byte[] SubLine;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)]
public byte[] PoleName;
public byte interval;
public byte DevCount;
}
可以理论上来说应该第一个是6字节,第二个结构体是114字节
可我用Marshal.SizeOf()算出来的第一个是8字节,第二个是116字节都多出来两字节
不知道为什么?
public struct FileStruct
{
public byte FileId;
public byte FileVar;
public Int32 RecCount;
}