Code
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5using System.Runtime.Serialization.Formatters.Binary;
6
7namespace SerializeTest
8{
9 [Serializable]
10 class A
11 {
12
13 }
14 class Program
15 {
16 static void Main(string[] args)
17 {
18 try
19 {
20 A a = new A();
21 FileStream fs = new FileStream("D:\\A.mdy", FileMode.Create);
22 BinaryFormatter bf = new BinaryFormatter();
23 bf.Serialize(fs, a);
24 }
25 catch(Exception ex)
26 {
27 Console.Write(ex.Message);
28 }
29 }
30 }
31}
32
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5using System.Runtime.Serialization.Formatters.Binary;
6
7namespace SerializeTest
8{
9 [Serializable]
10 class A
11 {
12
13 }
14 class Program
15 {
16 static void Main(string[] args)
17 {
18 try
19 {
20 A a = new A();
21 FileStream fs = new FileStream("D:\\A.mdy", FileMode.Create);
22 BinaryFormatter bf = new BinaryFormatter();
23 bf.Serialize(fs, a);
24 }
25 catch(Exception ex)
26 {
27 Console.Write(ex.Message);
28 }
29 }
30 }
31}
32