[StructLayout(LayoutKind.Sequential, Pack=1)] public struct DT3 { public short a3; public short b3; }
[StructLayout(LayoutKind.Sequential, Pack=1)] public struct DT2 { public short a2; public short b2; }
[StructLayout(LayoutKind.Sequential, Pack=1)] public struct DT1 { [MarshalAs(UnmanagedType.ByValArray, SizeConst=16)] public DT2[] dt2; public short a1; [MarshalAs(UnmanagedType.ByValArray, SizeConst=5)] public DT3[] dt3; }
[StructLayout(LayoutKind.Sequential, Pack=1)] public struct DT { public int a0; public DT1 dt1; }
static public DT dt;
private void test() { text1.Text = dt.a0; ... @ }
private void test() { text1.Text = dt.dt1.a1; ... A }
private void test() { text1.Text = dt.dt1.dt2.a2; ... B }
分類:[.NET]
C#2005で開発しています。
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct DT3
{
public short a3;
public short b3;
}
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct DT2
{
public short a2;
public short b2;
}
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct DT1
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=16)]
public DT2[] dt2;
public short a1;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=5)]
public DT3[] dt3;
}
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct DT
{
public int a0;
public DT1 dt1;
}
static public DT dt;
private void test()
{
text1.Text = dt.a0; ... @
}
private void test()
{
text1.Text = dt.dt1.a1; ... A
}
private void test()
{
text1.Text = dt.dt1.dt2.a2; ... B
}
上記で、@、Aは問題なく参照できるのですが、Bの場合、
「オブジェクト参照がオブジェクトインスタンスに設定されていません」
となります。
どうすればいいのかご教授下さい。