// Execution starts here. static void Main() { BookDB bookDB = new BookDB(); // Initialize the database with some books: AddBooks(bookDB); // Print all the titles of paperbacks: System.Console.WriteLine("Paperback Book Titles:"); // Create a new delegate object associated with the static // method Test.PrintTitle: bookDB.ProcessPaperbackBooks(PrintTitle); // Get the average price of a paperback by using // a PriceTotaller object: PriceTotaller totaller = new PriceTotaller(); // Create a new delegate object associated with the nonstatic // method AddBookToTotal on the object totaller: bookDB.ProcessPaperbackBooks(totaller.AddBookToTotal); System.Console.WriteLine("Average Paperback Book Price: ${0:#.##}", totaller.AveragePrice()); Console.ReadLine(); }
// Execution starts here. private static void Main() { var bookDb = new BookDb(); // Initialize the database with some books: AddBooks(bookDb); // Print all the titles of paperbacks: Console.WriteLine("Paperback Book Titles:"); // Create a new delegate object associated with the static // method Test.PrintTitle: bookDb.ProcessPaperbackBooks(new ProcessBookDelegate(PrintTitle)); //bookDb.ProcessPaperbackBooks(PrintTitle); // Get the average price of a paperback by using // a PriceTotaller object: PriceTotaller totaller = new PriceTotaller(); // Create a new delegate object associated with the nonstatic // method AddBookToTotal on the object totaller: bookDb.ProcessPaperbackBooks(new ProcessBookDelegate(totaller.AddBookToTotal)); //bookDb.ProcessPaperbackBooks(totaller.AddBookToTotal); Console.WriteLine("Average Paperback Book Price: ${0:#.##}", totaller.AveragePrice()); Console.ReadLine(); }
// Execution starts here. static void Main() { BookDB bookDB = new BookDB(); // Initialize the database with some books: AddBooks(bookDB); // Print all the titles of paperbacks: System.Console.WriteLine("Paperback Book Titles:"); // Create a new delegate object associated with the static // method Test.PrintTitle: bookDB.ProcessPaperbackBooks(PrintTitle); // bookDB.ProcessPaperbackBooks(Console.WriteLine); // Get the average price of a paperback by using // a PriceTotaller object: PriceTotaller totaller = new PriceTotaller(); // Create a new delegate object associated with the nonstatic // method AddBookToTotal on the object totaller: ProcessBookDelegate myfunc = totaller.AddBookToTotal; myfunc += totaller.FindDistinctAuthors; bookDB.ProcessPaperbackBooks(myfunc); System.Console.WriteLine("Average Paperback Book Price: ${0:#.##}", totaller.AveragePrice()); totaller.ShowAllAuthors(); }