c#的序列化问题
我要序列化一个结构体
byte[] askdata=new byte[1024];
AskData askTemperatureData=new AskData();
askTemperatureData.bt=new byte[4]{23,255,255,1};
askTemperatureData.s = new ushort[] { 1,1,10};
askTemperatureData.num = 1;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
bf.Serialize(stream, askTemperatureData);
askdata = stream.ToArray();
运行后报错,请问该怎样修改
c#
序列化
------解决方案--------------------AskData类要标记可序列化,在AskData的类定义上加上[Serializable()]
[Serializable()]
public class AskData
{
..
}