struct TestStruct
{
public int f1;
public int f2;
public char f3;
}
TestStruct ts1=new TestStruct();
ts1.f1=47;
ts1.f2=876;
ts1.f3='s';
int s=Marshal.SizeOf(ts1.GetType());
IntPtr p=Marshal.AllocHGlobal(s);
Marshal.StructureToPtr(ts1,p,true);
byte[] bs=new byte;
Marshal.Copy(p,bs,0,s);
Marshal.FreeHGlobal(p);