手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#反序列化到类的实现方法
C#反序列化到类的实现方法
摘要:本文实例讲述了C#反序列化到类的实现方法。分享给大家供大家参考。具体实现方法如下:usingSystem;usingSystem.Colle...

本文实例讲述了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#程序设计有所帮助。

【C#反序列化到类的实现方法】相关文章:

C#用Lambda和委托实现模板方法

c#简单读取文本的实例方法

解决C#获取鼠标相对当前窗口坐标的实现方法

C#中读写INI文件的方法例子

c#之滚动字幕动画窗体的实现详解

在C#中创建和读取XML文件的实现方法

C# 屏蔽关键字的实现方法

C#最简单的关闭子窗体更新父窗体的实现方法

c#生成缩略图的实现方法

C#技巧之快速删除bin和obj文件夹的方法

精品推荐
分类导航