using System.Runtime.Serialization.Formatters.Soap;
namespace Serialize
{
public partial class Form1 : Form
{
Human Kim = new Human("..", n);
..
private void button1_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream(@"..", FileMode.Create, FileAccess.Write);
SoapFormatter sf = new SoapFormatter();
sf.Serialize(fs, Kim);
fs.Close();
}
private void button2_Click(object sender, EventArgs e)
{
..
FileStream fs = new FileStream(@"..", FileMode.Open, FileAccess.Read);
SoapFormatter sf = new SoapFormatter();
Kim = (Human)sf.Deserialize(fs);
fs.Close();
..
}
}
[Serializable]
class Human
{
private string Name;
private int Age;
[NonSerialized]
private float Temp;
public Human(string aName, int aAge)
{
Name = aName;
Age = aAge;
Temp = ..;
}
..
}
}