using System;
using System.Runtime.InteropServices;
class test
{
[StructLayout(LayoutKind.Explicit)]
public struct tmp
{
[FieldOffset(0)]
public int i;
[FieldOffset(4)]
public int f;
}
[MarshalAs(UnmanagedType.LPStruct)]
static tmp[] b;
public unsafe static void Main()
{
tmp[] a;
a = new tmp[2];
a[0].i = 10;
a[0].f = 10;
a[1].i = 20;
a[1].f = 20;
b = a;
fixed (tmp* p = b)
{
tmp* ps = p;
for (int i = 0; i < 2; i++)
{
Console.WriteLine("{0}", *((int*)ps));
Console.WriteLine("{0}", *((int*)(ps+4)));
}
}
}
}
|