コード例 #1
0
        /// <summary>
        /// Displays current books in library and takes a user input to remove book from library and
        /// store the book in the BookBag.
        /// </summary>
        public static void BorrowABook()
        {
            Console.WriteLine("Which book would you like to borrow?");
            int displayCount = 1;

            foreach (Book book in myLibrary)
            {
                if (book != null)
                {
                    Console.WriteLine($"{displayCount}: {book.Title} by {book.Author.FirstName} {book.Author.LastName}." +
                                      $" Genre: {book.Genre}");
                    displayCount++;
                }
            }
            string userChoice = Console.ReadLine();

            Book chosenBook = myLibrary.Remove(Convert.ToInt32(userChoice) - 1);

            if (chosenBook == null)
            {
                Console.WriteLine("Could not find book! Please try again.");
            }
            else
            {
                BookBag.Add(chosenBook);
                myLibrary.GetEnumerator();
                Console.WriteLine($"{chosenBook.Title} added to Book Bag!");
            }
            Console.WriteLine();
        }