//序列化
//Person p=new Person();
//p.Name="夏华成";
//p.Age=29;
//BinaryFormatter bf = new BinaryFormatter();
//using(FileStream fs=new FileStream("xhc",FileMode.Create))
//{
// bf.Serialize(fs, p);
//}
//Console.WriteLine("OK");
//反序列化
BinaryFormatter bf = new BinaryFormatter();
using (FileStream fs = new FileStream("xhc", FileMode.Open))
{
Person p=(Person)bf.Deserialize(fs);
Console.WriteLine("姓名:{0};年龄{1}",p.Name,p.Age);
}
Console.ReadKey();
[Serializable]
class Person
{
private int _age;
public int Age
{
set {
_age = value;
}
get {
return _age;
}
}
private string _name;
public string Name
{
set {
_name = value;
}
get
{
return _name;
}
}
}