Example #1
0
        // Execution starts here.
        static void Main()
        {
            BookDB bookDB = new BookDB();

            // Initialize the database with some books:
            AddBooks(bookDB);

            // Print all the titles of paperbacks:
            Console.WriteLine("Paperback Book Titles:");

            // FIXME en hier is het nog eens!
            // Create a new delegate object associated with the static
            // method Test.PrintTitle:
            bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(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));
            Console.WriteLine("Average Paperback Book Price: ${0:#.##}",
                              totaller.AveragePrice());
        }
Example #2
0
        //第 0 個參數佔 30 字元(靠右); 第 1 個參數格式化為 #.##
        //{ System.Console.WriteLine("{0,30} = {1:#.##}", b.Title, b.Price); }
        //http://blog.csdn.net/xrongzhen/article/details/5477075

        // Execution starts here.
        static void Main()
        {
            BookDB bookDB = new BookDB(); //為命名空間 Bookstore 之類別 BookDB 建立實體

            // Initialize the database with some books:
            bookDB.AddBook("The C Programming Language", "Brian W.", 19.95m, true);
            bookDB.AddBook("The Unicode Standard 2.0", "The Unicode Consortium", 39.95m, true);
            System.Console.WriteLine("Paperback Book Titles:");

            // Create a new delegate object associated with the static
            // method PrintTitle: 指向靜態方法之委派
            bookDB.ProcessPaperbackBooks(PrintTitle); //書籍名稱 (逐本處理)

            // Get the average price of a paperback by using a PriceTotaller object:
            PriceTotaller totaller = new PriceTotaller(); //為類別 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());

            string nop = System.Console.ReadLine();
        }
Example #3
0
        // 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:");

            //声明了委托类型后,必须创建委托对象并使之与特定方法关联。
            //通过按下面示例中的方式将 PrintTitle 方法传递到 ProcessPaperbackBooks 方法来实现这一点
            //ProcessPaperbackBooks以委托作为参数方便传入方法
            bookDB.ProcessPaperbackBooks(PrintTitle);   //注意这里只是方法引用赋值给委托,所以没有()

            PriceTotaller totaller = new PriceTotaller();

            //ProcessPaperbackBooks()的参数是委托类型的,传入的是totaller.AddBookToTotal方法
            //通过遍历将金额相加
            bookDB.ProcessPaperbackBooks(totaller.AddBookToTotal);

            System.Console.WriteLine("Average Paperback Book Price: ${0:#.##}",
                                     totaller.AveragePrice());
            Console.ReadKey();
        }
Example #4
0
        static void Main()
        {
            BookDB bookDB = new BookDB();

            AddBooks(bookDB);
            Console.WriteLine("paperback book titles: ");

            Console.WriteLine("DELEGATE CALL 1");
            bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(PrintTitle));//METODER SOM TAR EMOT BOK SOM INPARAMETER OCH RETURNERAR VOID

            PriceTotaller totaller = new PriceTotaller();

            Console.WriteLine("DELEGATE CALL 2");
            bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(totaller.AddBookToTotal));//inserting pricetotaller object into delegate that only takes book? //METODER SOM TAR EMOT BOK SOM INPARAMETER OCH RETURNERAR VOID
            Console.WriteLine("Average paperback book price ${0:#.##}", totaller.AveragePrice());
            Console.ReadKey();


            //random test
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("_________________________");
            TextAdderToBook adder = new TextAdderToBook();

            bookDB.ProcessPaperbackBooks(adder.AddTextToBookTitle);
            Console.ResetColor();
        }
Example #5
0
        static void Main0()
        {
            BookDB bookDB = new BookDB();

            AddBooks(bookDB);
            Console.WriteLine("Paperback Book Titles:");
            bookDB.ProcessPaperbackBooks(PrintTitle);
            PriceTotaller totaller = new PriceTotaller();

            bookDB.ProcessPaperbackBooks(totaller.AddBookToTotal);
            Console.WriteLine("Average Parperback Book Price:${0:#.##}", totaller.AveragePrice());
        }
Example #6
0
        public static void Main(string[] args)
        {
            BookDB bookDB = new BookDB();

            AddBooks(bookDB);
            Console.WriteLine("PaperBack Book Titles:");
            bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(PrintTitle));
            PriceTotaller totaller = new PriceTotaller();

            bookDB.ProcessPaperbackBooks(totaller.AddBookToTotal);
            Console.WriteLine("Average Paperback Book Price: ${0:#.##}", totaller.AveragePrice());
            Console.ReadKey();
        }
Example #7
0
        static void Main()
        {
            BookDB bookDB = new BookDB();

            AddBooks(bookDB);

            Console.WriteLine("Paperback book titles:");
            bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(PrintTitle));

            PriceTotaller totaller = new PriceTotaller();

            bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(totaller.AddBookToTotal));
            Console.WriteLine("Average Paperback book price: {0:#.##}", totaller.AveragePrice());
        }
Example #8
0
        // Execution starts here.
        static void Main()
        {
            BookStore bookStore = new BookStore();

            // Initialize the database with some books:
            AddBooks(bookStore);

            // Print all the titles of paperbacks:
            Console.WriteLine("Paperback Book Titles:");
            // Create a new delegate object associated with the static method Test.PrintTitle:
            // in oudere C# versies:
            // bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(PrintTitle));
            bookStore.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:
            bookStore.ProcessPaperbackBooks(totaller.AddBookToTotal);
            Console.WriteLine($"Average Paperback Book Price: {totaller.AveragePrice():#.##}");
        }
Example #9
0
        // 下面开始执行。
        static void Main()
        {
            BookDB bookDB = new BookDB();

            // 用一些书初始化数据库:
            AddBooks(bookDB);

            // 打印所有平装本的书名:
            Console.WriteLine("Paperback Book Titles:");
            // 创建一个与静态方法 Test.PrintTitle 关联的
            // 新委托对象:
            bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(PrintTitle));

            // 使用 PriceTotaller 对象
            // 获取平装本的平均价格:
            PriceTotaller totaller = new PriceTotaller();

            // 创建一个与对象 totaller 的非静态方法
            // AddBookToTotal 关联的新委托对象:
            bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(totaller.AddBookToTotal));
            Console.WriteLine("Average Paperback Book Price: ${0:#.##}",
                              totaller.AveragePrice());
        }
Example #10
0
        // Выполнение начинается здесь.
        static void Main()
        {
            BookDB bookDB = new BookDB();

            // Инициализация базы данных с использованием нескольких книг:
            AddBooks(bookDB);

            // Печать названий всех книг в бумажной обложке:
            Console.WriteLine("Paperback Book Titles:");
            // Создание нового объекта делегата, связанного со статическим
            // методом Test.PrintTitle:
            bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(PrintTitle));

            // Получение средней цены книги в бумажной обложке при помощи
            // объекта PriceTotaller:
            PriceTotaller totaller = new PriceTotaller();

            // Создание нового объекта-делегата, связанного с нестатическим объектом
            // методом AddBookToTotal объекта суммарных показателей:
            bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(totaller.AddBookToTotal));
            Console.WriteLine("Average Paperback Book Price: ${0:#.##}",
                              totaller.AveragePrice());
        }
Example #11
0
        // Execution starts here.
        static void Main( )
        {
            BookDB 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 ) );

            // 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 ) );
            Console.WriteLine( "Average Paperback Book Price: ${0:#.##}",
               totaller.AveragePrice( ) );
        }
Example #12
0
      static void Main() // Выполнение начинается здесь.
      {
         BookDB bookDB = new BookDB();

         
         AddBooks(bookDB);      // Инициализация базы данных с использованием нескольких книг:

         
         Console.WriteLine("Paperback Book Titles:");  // Печать названий всех книг в бумажной обложке:

         // Создание нового объекта делегата, связанного со статическим методом Test.PrintTitle:
         bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(PrintTitle));

         // Получение средней цены книги в бумажной обложке при помощи объекта PriceTotaller:
         PriceTotaller totaller = new PriceTotaller();

         // Создание нового объекта-делегата, связанного с нестатическим объектом 
         // методом AddBookToTotal объекта суммарных показателей:
         bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(totaller.AddBookToTotal));

         Console.WriteLine("Average Paperback Book Price: ${0:#.##}", totaller.AveragePrice() );
      }
Example #13
0
        // 下面开始执行。
        static void Main()
        {
            BookDB bookDB = new BookDB();

             // 用一些书初始化数据库:
             AddBooks(bookDB);

             // 打印所有平装本的书名:
             Console.WriteLine("Paperback Book Titles:");
             // 创建一个与静态方法 Test.PrintTitle 关联的
             // 新委托对象:
             bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(PrintTitle));

             // 使用 PriceTotaller 对象
             // 获取平装本的平均价格:
             PriceTotaller totaller = new PriceTotaller();
             // 创建一个与对象 totaller 的非静态方法
             // AddBookToTotal 关联的新委托对象:
             bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(totaller.AddBookToTotal));
             Console.WriteLine("Average Paperback Book Price: ${0:#.##}",
            totaller.AveragePrice());
        }
Example #14
0
 static void Main()
 {
     BookDB bookDB = new BookDB();
     AddBooks(bookDB);
     Console.WriteLine("Paperback Book Titles:");
     bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(PrintTitle));
     PriceTotaller totaller = new PriceTotaller();
     bookDB.ProcessPaperbackBooks(new ProcessBookDelegate(totaller.AddBookToTotal));
     Console.WriteLine("Average Paperback Book Price: ${0:#.##}", totaller.AveragePrice());
     Console.ReadLine();
 }