C# 二进制BinaryFormatter进行序列化与反序列化
voidDeserializeMethod()// 二进制反序列化
{
FileStream fs =newFileStream (filePath, FileMode.Open);
BinaryFormatter bf =newBinaryFormatter ();
List list = bf.Deserialize (fs)as List;
if(list !=null){
for(int i = 0; i < list.Count; i++){
//list [I] do something
}}
fs.Close ();
}
voidSerializeMethod(List listPers)// 二进制序列化
{
FileStream fs =newFileStream (filePath, FileMode.Create);
BinaryFormatter bf =newBinaryFormatter ();
bf.Serialize (fs, listPers);
fs.Close ();
}
赞 (0)