我把对象转换字节是这样的:
public byte[] GetBytes<T>(NMT_DATA<T> data)
{
int size = Marshal.SizeOf(data);
IntPtr buffer = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(data, buffer, true);
byte[] rawdatas = new byte[size];
Marshal.Copy(buffer, rawdatas, 0, size);
Marshal.FreeHGlobal(buffer);
return rawdatas;
}
这样可以的呃
public byte[] GetBytes<T>(T data)
{
int size = Marshal.SizeOf(data);
IntPtr buffer = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(data, buffer, true);
byte[] rawdatas = new byte[size];
Marshal.Copy(buffer, rawdatas, 0, size);
Marshal.FreeHGlobal(buffer);
return rawdatas;
}
序列化么~~~