static void Main(string[] args) { FileStream stream = new FileStream(@"c:\csh\Emp.txt", FileMode.OpenOrCreate, FileAccess.Read); BinaryFormatter formatter = new BinaryFormatter(); Employ e = (Employ)formatter.Deserialize(stream); Console.WriteLine(e.Empno); Console.WriteLine(e.Name); Console.WriteLine(e.Basic); }
static void Main(string[] args) { FileStream fs = new FileStream(@"c:\files\Emp.txt", FileMode.Create, FileAccess.Write); BinaryFormatter form = new BinaryFormatter(); Employ e = new Employ(); e.Empno = 1; e.Name = "asdfasf"; e.Basic = 88233; form.Serialize(fs, e); fs.Close(); }