public IEnumerable<Book> LoadBooks() { List<Book> books = new List<Book>(); try { using (FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read)) { using (BinaryReader bw = new BinaryReader(fs)) { long position = bw.BaseStream.Position; while (position < bw.BaseStream.Length) { Book book = new Book(bw.ReadString(), bw.ReadString(), bw.ReadString(), bw.ReadInt32(), bw.ReadInt32(), bw.ReadInt32()); books.Add(book); position = bw.BaseStream.Position; } } } } catch (Exception e) { books.Clear(); books.TrimExcess(); throw new IOException("Error while loading books from file.", e); } return books; }
static void Main() { var book = new Book(10); book.AddRange(3, 4); book.AddRange(6, 8); var left = book.HowManyPagesLeft(); Console.WriteLine("Left: " + left); }
public bool DeleteBook(Book bookForDeletion) { return bls.DeleteBook(bookForDeletion); }
public int IndexOfBook(Book book) { return bls.IndexOfBook(book); }
public bool AddBook(Book bookToAdd) { return bls.AddBook(bookToAdd); }