using System; // Console
using System.IO; // FileStream
using System.Collections; // ArrayList
using System.Runtime.Serialization; // IFormatter
using System.Runtime.Serialization.Formatters.Binary; // BinaryFormatter
namespace Serialization_b
{
class Class1
{
static void Main(string[] args)
{
ArrayList al = new ArrayList();
for (int i = 0; i < 10; i++)
al.Add (i);
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("d:\\foo.bin", FileMode.Create, FileAccess.Write, FileShare.None);
formatter.Serialize(stream, al);
stream.Close();
ArrayList al2 = new ArrayList();
stream = new FileStream("d:\\foo.bin", FileMode.Open, FileAccess.Read, FileShare.Read);
al2 = (ArrayList)formatter.Deserialize(stream);
stream.Close();
foreach (int i in al2)
Console.WriteLine(i);
}
}
}
/*
run:
0
1
2
3
4
5
6
7
8
9
*/