tomatomax.net

Every rule has its exception.

構造体と配列

構造体の中に配列を埋める方法がわからなかったのでメモ。

Unmanagedでは

struct box {
int a[10];
};

これをManagedで実現しようとしたとき。

[StructLayout(LayoutKind.Sequential)]
public struct box {
[MarshalAs(UnmanagedType.ByValArray, SizeConst=10)] public int[] a;
}

(;´∀`)……

さらに、使うときには配列のインスタンスを作成する必要があるようで。

Leave a Reply