搞不懂为什么要序列化。序列化作用是什么,一般用在哪些场合

解决方案 »

  1.   

    持久化程序运行时信息反序列就把保存的信息在运行时还原cnForum论坛有这方面运用的  就是把一些不需要查询的附加信息序列化存储在数据库中
      

  2.   

    序列化方便对象的传输及储存;
    它能将对象转成如XML/Bit流;
    它是Session(进程外/SqlServer模式),ViewState,WebService,Remoting等的基础。
      

  3.   

    例如学生类
    public class Student
    {
    public int id;
    public string name;
    public bool sex;
    public DateTime birthday;
    ...
    }// 序列化为byte[]
    MemoryStream fs = new MemoryStream();
    byte[] tmp = null;
    BinaryFormatter formatter = new BinaryFormatter();
    formatter.Serialize(fs, student);
    tmp = fs.ToArray();
    将tmp作为bianry数据存到数据库// 反序列化直接生成Student类
    MemoryStream fs = new MemoryStream();
    Student student = null;
    fs = new MemoryStream(tmp);
    fs.Position = 0;
    BinaryFormatter formatter = new BinaryFormatter();
    student = formatter.Deserialize(fs);
    操作方便不用一一赋值。不过也有一些问题,如存到数据库以后,类Student又添加了属性,于是就反序列化不出来了!
      

  4.   

    一般情况下逆势感觉不到的比如在webservice中和remoting中都会用到
      

  5.   

    比如在webservice中和remoting中都会用到
    能否在这方面举个例子说明一下。