static void StreamToFile() { Console.Write("Enter first name: "); string firstName = Console.ReadLine(); Console.Write("Enter last name: "); string lastName = Console.ReadLine(); Employee employee = new Employee(lastName, firstName); BinaryFormatter bf = new BinaryFormatter(); using(FileStream fs = File.OpenWrite("employee.txt")) { bf.Serialize(fs, employee); } using(FileStream fs = File.OpenRead("employee.txt")) { Employee obj = (Employee)bf.Deserialize(fs); Console.WriteLine(obj); } }
internal void AddEmployee(Employee e) { if (employees.Count < employees.Capacity) { this[employees.Count] = e; } }