static void Main(string[] args) { BookDataBase db = new BookDataBase(); List <Book> list = new List <Book>(); db.AddBook("alice", "Carrol", 10, true); db.AddBook("lotr", "Tolkien", 15, true); db.AddBook("game of thrones", "Martin", 20, true); db.AddBook("kolobok", "unknown", 30, true); // Pass delegate into class method //db.ProcessBooks(PrintTitle); PriceCounter totaller = new PriceCounter(); // db.ProcessBooks(totaller.AddBookToTotal); //Console.WriteLine(totaller.AvaragePrice()); // Declaring delegate as instance DoSomethingWithBook getPrice = totaller.GetPrice; DoSomethingWithBook totalBooks = totaller.AddBookToTotal; // Delegates can be joined DoSomethingWithBook joined = getPrice + totalBooks; db.ProcessBooks(joined); totaller.PrintPrices(); Console.WriteLine("Average books price is {0}", totaller.AvaragePrice()); Console.ReadLine(); }
public void ProcessBooks(DoSomethingWithBook process) { foreach (Book b in listOfBooks) { process(b); } }