当前位置: 移动技术网 > IT编程>开发语言>c# > C#反序列化到类的实现方法

C#反序列化到类的实现方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例讲述了c#反序列化到类的实现方法。分享给大家供大家参考。具体实现方法如下:

using system;
using system.collections.generic;
using system.linq;
using system.runtime.serialization.formatters.binary;
using system.text;
using system.threading.tasks;
using system.io;
using 二进制序列化;
namespace 反序列化
{
  class program
  {
    static void main(string[] args)
    {
      binaryformatter bf = new binaryformatter();
      using (filestream fs = new filestream ("person.bin",filemode.open))
      {
        object obj = bf.deserialize(fs);
        people p = (people)obj;
        console.writeline("姓名:{0}\t年龄:{1}",p.name ,p.age);
      }
      console.writeline("反序列化完毕!");
      console.readkey();
    }
  }
}

这里注意反序列化时需要引用people类所在的程序集

希望本文所述对大家的c#程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网