public List<Book> Read() { List<Book> Libraly = new List<Book>(); using (StreamReader sr = new StreamReader("books.txt")) { while (!sr.EndOfStream) { Book tempBook = new Book(); tempBook.AuthorName = sr.ReadLine(); tempBook.AuthorSurename = sr.ReadLine(); tempBook.Title = Console.ReadLine(); tempBook.Publishing = sr.ReadLine(); tempBook.Year = sr.ReadLine(); Libraly.Add(tempBook); } } return Libraly; }
public void Add() { Book tempBook = new Book(); Console.Write("Имя автора:"); tempBook.AuthorName = Console.ReadLine(); Console.Write("Фамилия автора:"); tempBook.AuthorSurename = Console.ReadLine(); Console.Write("Назваие:"); tempBook.Title = Console.ReadLine(); Console.Write("Издательство:"); tempBook.Publishing = Console.ReadLine(); Console.Write("Год издания:"); tempBook.Year = Console.ReadLine(); Libraly.Add(tempBook); using (StreamWriter sw = new StreamWriter("Books.txt", true)) { sw.WriteLine(); sw.WriteLine(tempBook.AuthorName); sw.WriteLine(tempBook.AuthorSurename); sw.WriteLine(tempBook.Title); sw.WriteLine(tempBook.Publishing); sw.Write(tempBook.Year); } }