您的位置:首页 > 其它

使用序列化保存对象状态到存储介质

2016-12-05 21:48 190 查看
//使用序列化保存对象状态到存储介质
//添加[Serializable]
Game game = new Game();
game.Level = 2;
game.Player = "Tom";
FileStream fs = new FileStream(@"game.bin",FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs,game);

//使用反序列化从存储介质读取对象状态
Game game = new Game();
FileStream fs = new FileStream(@"game.bin",FileMode.Open,FileAccess.Read);
BinaryFormatter bf = new BinaryFormatter();
game = (Game)bf.Deserialize(fs);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐