我有一个名为“ItemToPlace”的课程
[Serializable()]
private class ItemToPlace
{
public ItemToPlace(int ID, float x, float y)
{
this.ID = ID;
this.X = x;
this.Y = y;
}
public ItemToPlace()
{
}
public int ID { get; set; }
public float X { get; set; }
public float Y { get; set; }
}
我有一个
List<ItemToPlace> items;
我按如下方式序列化列表:
Stream stream = File.Open("Data.dat", FileMode.Create);
BinaryFormatter bformatter = new BinaryFormatter();
bformatter.Serialize(stream, items);
stream.Close();
反序列化列表返回null
Stream stream = File.Open("Data.dat", FileMode.Open);
BinaryFormatter bformatter = new BinaryFormatter();
// level = null
level = bformatter.Deserialize(stream) as List<ItemToPlace>;
stream.Close();
我不知道为什么这不起作用!任何暗示都会很好!