首页 > 其他 > 详细

<C#>序列化

时间:2014-07-14 15:22:19      阅读:368      评论:0      收藏:0      [点我收藏+]

序列化就是为了简化复杂的数据结构的存储提出来的概念。

序列化也就是把类的对象作为一个整体存入文件,反序列化则是相反过程

#using System;
#using System.IO;
#using System.Collections.Generic;
#using System.Runtime.Serialization.Formatters.Binary;
#using System.Runtime.Serialization;

class SerialFile
{
    static void Main()
   {
             Dictionary<string,string>  h = new Dictionary<string,string>();
             h.Add("Key1","Value1");
             h.Add("Key2","Value2");
             FileStream fs = new FileStream(@"d:/d.dat",FileMode.Create);
             BinaryFormatter formatter = new BinaryFormatter();
             formatter.Serialize(fs,h);
             fs.close();
             fs = new FileStream(@"d:/d.dat",FileMode.Open);
             h.Clear();
             h = (Dictionary<string,string>)formatter.Deserialize(fs);
             fs.Close();
             foreach(KeyValuePair<string,string> h1 in h)
             {
                       Console.WriteLine{"{0}:{1}",h1.Key,h1.Value};
              }
   }  
}    

 

<C#>序列化,布布扣,bubuko.com

<C#>序列化

原文:http://www.cnblogs.com/virgil/p/3841688.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!