Look at this site: http://www.developerfusion.com/article/84519/mastering-structs-in-c/
I think you will want more control over your data types especially with Serialize/Deserializing your data. This will allow you to control EXACTLY how you marshall your datatypes.
Taken Directly from Mastering Structs in C#
Struct Layout
[StructLayout(LayoutKind.Sequential,
Pack = 1, CharSet = CharSet.Unicode)]
public struct DISPLAY_DEVICE
{
public int cb;
[MarshalAs(
UnmanagedType.ByValArray,
SizeConst=32)]
public char[] DeviceName;
[MarshalAs(
UnmanagedType.ByValArray,
SizeConst=128)]
public char[] DeviceString;
public int StateFlags;
[MarshalAs(
UnmanagedType.ByValArray,
SizeConst = 128)]
public char[] DeviceID;
[MarshalAs(
UnmanagedType.ByValArray,
SizeConst = 128)]
public char[] DeviceKey;
}
Serialization
public static byte[]
RawSerialize(object anything)
{
int rawsize =
Marshal.SizeOf(anything);
IntPtr buffer =
Marshal.AllocHGlobal(rawsize);
Marshal.StructureToPtr(anything,
buffer, false);
byte[] rawdata = new byte[rawsize];
Marshal.Copy(buffer, rawdata,
0, rawsize);
Marshal.FreeHGlobal(buffer);
return rawdata;
}
Side note:
For basic serialization I would not try to roll my own I would just use built in .NET serialization: http://msdn.microsoft.com/en-us/library/4abbf6k0.aspx