public struct Label1 { public BYTE LabFilterChan0[4,256]; public BYTE LabFilterChan1[4,256];
}
public class Label1 { byte[,]LabFilterChan0 = new byte[4,256]; byte[,]LabFilterChan1 = new byte[4, 256];}
[StructLayout(LayoutKind.Sequential)] public class Label1 { public byte[,] LabFilterChan0 = new byte[4, 256]; public byte[,] LabFilterChan1 = new byte[4, 256]; }
public struct Label1 { byte[,]LabFilterChan0 = new byte[4,256]; byte[,]LabFilterChan1 = new byte[4, 256];}默认就是 [StructLayout(LayoutKind.Sequential)]
上面的都有问题:3楼,内存空间为8,与C++严重不对应! 4楼,语法就编译错误!对于结构体二维数组,看似简单,其实很复杂。正确做法: [StructLayout(LayoutKind.Sequential)] public struct ByteStru { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] public byte[] a; }; [StructLayout(LayoutKind.Sequential)] public struct Label1 { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public ByteStru[] LabFilterChan0 ; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public ByteStru[] LabFilterChan1 ; };
{
public BYTE LabFilterChan0[4,256];
public BYTE LabFilterChan1[4,256];
}
public class Label1
{
byte[,]LabFilterChan0 = new byte[4,256];
byte[,]LabFilterChan1 = new byte[4, 256];}
public class Label1
{
public byte[,] LabFilterChan0 = new byte[4, 256];
public byte[,] LabFilterChan1 = new byte[4, 256];
}
{
byte[,]LabFilterChan0 = new byte[4,256];
byte[,]LabFilterChan1 = new byte[4, 256];}默认就是 [StructLayout(LayoutKind.Sequential)]
4楼,语法就编译错误!对于结构体二维数组,看似简单,其实很复杂。正确做法: [StructLayout(LayoutKind.Sequential)]
public struct ByteStru
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public byte[] a;
}; [StructLayout(LayoutKind.Sequential)]
public struct Label1
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public ByteStru[] LabFilterChan0 ;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public ByteStru[] LabFilterChan1 ;
};
(突破自我)
认真回复。