3 using System
.Runtime
.Serialization
;
4 using System
.Runtime
.Serialization
.Formatters
.Binary
;
7 public class Tuple
<a
,b
> {
11 public Tuple (a x
, b y
) {
19 public static void Main() {
21 //Creates a new TestSimpleObject object.
22 TestSimpleObject obj
= new TestSimpleObject();
24 Console
.WriteLine("Before serialization the object contains: ");
27 //Opens a file and serializes the object into it in binary format.
28 Stream stream
= File
.Open("data.xml", FileMode
.Create
);
29 BinaryFormatter formatter
= new BinaryFormatter();
31 //BinaryFormatter formatter = new BinaryFormatter();
33 formatter
.Serialize(stream
, obj
);
39 //Opens file "data.xml" and deserializes the object from it.
40 stream
= File
.Open("data.xml", FileMode
.Open
);
41 formatter
= new BinaryFormatter();
43 //formatter = new BinaryFormatter();
45 obj
= (TestSimpleObject
)formatter
.Deserialize(stream
);
48 Console
.WriteLine("");
49 Console
.WriteLine("After deserialization the object contains: ");
55 // A test object that needs to be serialized.
57 public class TestSimpleObject
{
59 public Tuple
<string,int> member6
;
61 public TestSimpleObject() {
62 member6
= new Tuple
<string, int> ("aa", 22);
67 Console
.WriteLine("member6 = '{0}'", member6
);