对象序列化与反序列化

前端之家收集整理的这篇文章主要介绍了对象序列化与反序列化前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
 BinaryFormatter bf = new BinaryFormatter();
            //var list = new List<Person> {
            //    new Person{ Name="zhangsan",Sex='m',Age=10},//    new Person{ Name="lisi",Sex='f',Age=18},//    new Person{ Name="person3",Age=0}
            //};

            //bf.Serialize(File.Create("Person.bin"),list);
            //Console.WriteLine("OK");

            var lsPerson = (List<Person>)bf.Deserialize(File.OpenRead("Person.bin"));
            //XmlSerializer xml = new XmlSerializer(lsPerson.GetType());
            //xml.Serialize(File.OpenWrite("S:\\PersonInfo.xml"),lsPerson);   //序列化对象到xml文档中
            foreach (var item in lsPerson)
                Console.WriteLine(item.Name);

猜你在找的XML相关文章