I did
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Runtime.Serialization.Formatters.Binary; namespace WorkWithFile2 { class Program { [SerializableAttribute] struct Schedule { // id of the flight public string idPoleta; // direction public string flightWay; // date of departure public DateTime airDate; // the duration of the flight public int durationOfFlight; // the number of seats available public int freePlaces; } static void Main(string[] args) { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = new FileStream(@"C:\\Temp\\schedule.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); Schedule shd; int choise = 1; while (choise != 0 ) { Console.WriteLine("[1] - Add new flight"); Console.WriteLine("[2] - Show schedule."); Console.WriteLine("[0] Exit"); Console.Write("Choice: "); choise = int.Parse(Console.ReadLine()); switch (choise) { case 1: { Console.WriteLine("Add new flight"); Console.Write("Enter flight ID: "); shd.idPoleta = Console.ReadLine(); Console.Write("Enter the direction of flight: "); shd.flightWay = Console.ReadLine(); Console.Write("Enter the date and time of departure (approx. May 12 2016 12:36:55): "); shd.airDate = DateTime.Parse(Console.ReadLine()); Console.Write("Enter the flight duration in hours (approx.: 12): "); shd.durationOfFlight = int.Parse(Console.ReadLine()); Console.Write("Enter the number of available seats: "); shd.freePlaces = int.Parse(Console.ReadLine()); bf.Serialize(fs, shd); fs.Flush(); fs.Seek(0, SeekOrigin.Begin); shd = (Schedule)bf.Deserialize(fs); Console.WriteLine("Reis added."); Console.WriteLine("\\tID: {0}", shd.idPoleta); Console.WriteLine("\\tНаправление flight: {0}", shd.flightWay); Console.WriteLine("\\tДата and time of departure: {0}", shd.airDate.ToString("dd.MM.yyyy HH:mm")); Console.WriteLine("\\tПродолжительность flight: {0} hours", shd.durationOfFlight); Console.WriteLine("\\tКоличество seats available: {0}", shd.freePlaces); fs.Close(); break; } } } } } }
But then each new addition erases what is already added. How to make an Appendix with an existing and then display everything on the console screen?
Thanks for the help!