コード例 #1
0
        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;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: muroslavko/NET_CodeTesting
        static void Main()
        {
            var book = new Book(10);
            book.AddRange(3, 4);
            book.AddRange(6, 8);

            var left = book.HowManyPagesLeft();
            Console.WriteLine("Left: " + left);
        }
コード例 #3
0
 public bool DeleteBook(Book bookForDeletion)
 {
     return bls.DeleteBook(bookForDeletion);
 }
コード例 #4
0
 public int IndexOfBook(Book book)
 {
     return bls.IndexOfBook(book);
 }
コード例 #5
0
 public bool AddBook(Book bookToAdd)
 {
     return bls.AddBook(bookToAdd);
 }