posts - 77, comments - 54, trackbacks - 0, articles - 0
  IT博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

BinaryFormmater序列化!

Posted on 2006-08-14 18:06 东人EP 阅读(515) 评论(0)  编辑 收藏 引用 所属分类: .NET
 1 using  System;
 2 using  System.Collections.Generic;
 3 using  System.Text;
 4 using  System.IO;
 5 using  System.Runtime.Serialization;
 6 using  System.Runtime.Serialization.Formatters.Binary;
 7
 8 namespace  ConsoleApplication2
 9 {
10      class  BinaryFormatterSerialize
11      {
12          static   void  Main( string [] args)
13          {
14              /// /序列化
15              // SerializeTest st = new SerializeTest(120);
16              // SerializeTest st1 = new SerializeTest(300);
17              // BinaryFormatter bf = new BinaryFormatter();
18              // Stream sr = File.Open("E:\\Serialize.bat", FileMode.Append);
19              // bf.Serialize(sr, st);
20              // bf.Serialize(sr, st1);
21              // sr.Close();
22
23              // 反序列化
24             BinaryFormatter bf  =   new  BinaryFormatter();
25             Stream sread  =  File.OpenRead( " E:\\Serialize.bat " );
26             SerializeTest sst  =  (SerializeTest)bf.Deserialize(sread);
27             System.Console.WriteLine(sst.Test());
28             sread.Close();
29         }

30     }

31
32     [Serializable]
33      class  SerializeTest
34      {
35          public  SerializeTest( int  number)
36          {
37              this ._number  =  number;
38         }

39
40          private   int  _number;
41
42          public   int  Number
43          {
44              get   return  _number; }
45              set   { _number  =  value; }
46         }

47
48          public   string  Test()
49          {
50              return  Number.ToString();
51         }

52     }

53 }

54
只有注册用户登录后才能发表评论。