C#:Hashtable的序列化(保存和读取)

using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
....
...

Hashtable aa = new Hashtable();

private void buttonSave_Click(object sender, EventArgs e)
{
	FileStream fs = new FileStream("e:\\aa.dat", FileMode.Create);
	BinaryFormatter bf = new BinaryFormatter();
	bf.Serialize(fs, aa);
	fs.Close();
}

private void buttonLoad_Click(object sender, EventArgs e)
{
	aa.Clear();
	FileStream fs = new FileStream("e:\\aa.dat", FileMode.OpenOrCreate);
	BinaryFormatter bf = new BinaryFormatter();
	aa = (Hashtable)bf.Deserialize(fs);
	fs.Close();
}

转载于:https://www.cnblogs.com/lelf2005/archive/2008/10/07/1305411.html

你可能感兴趣的:(C#:Hashtable的序列化(保存和读取))