[C#] C#二进制序列化 →→→→→进入此内容的聊天室

来自 , 2020-09-05, 写在 C#, 查看 184 次.
URL http://www.code666.cn/view/9e1bf344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Runtime.Serialization.Formatters.Binary;
  7. using System.IO;
  8. namespace 二进制序列化
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             People p = new People();
  15.             p.Name = "许嵩";
  16.             p.Age = 28;
  17.             BinaryFormatter bf = new BinaryFormatter();
  18.             FileStream fs = new FileStream("person.bin", FileMode.Create);
  19.             bf.Serialize(fs,p);
  20.         }
  21.     }
  22.     [Serializable]
  23.     class People
  24.     {
  25.         string name;
  26.         public string Name
  27.         {
  28.             get { return name; }
  29.             set { name = value; }
  30.         }
  31.         int age;
  32.         public int Age
  33.         {
  34.             get { return age; }
  35.             set { age = value; }
  36.         }
  37.     }
  38. }
  39. //csharp/5476

回复 "C#二进制序列化"

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

captcha