[C#] C#反序列化到类的代码演示 →→→→→进入此内容的聊天室

来自 , 2021-02-22, 写在 C#, 查看 124 次.
URL http://www.code666.cn/view/70afbf22
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.Serialization.Formatters.Binary;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.IO;
  8. using 二进制序列化;
  9. namespace 反序列化
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             BinaryFormatter bf = new BinaryFormatter();
  16.             using (FileStream fs = new FileStream ("person.bin",FileMode.Open))
  17.             {
  18.                object obj =  bf.Deserialize(fs);
  19.                People p = (People)obj;
  20.                Console.WriteLine("姓名:{0}\t年龄:{1}",p.Name ,p.Age);
  21.             }
  22.             Console.WriteLine("反序列化完毕!");
  23.             Console.ReadKey();
  24.         }
  25.     }
  26. }
  27.  
  28.  
  29. //csharp/5455

回复 "C#反序列化到类的代码演示"

这儿你可以回复上面这条便签

captcha