Example #1
0
        static void Main(string[] args)
        {
            // actual execution begins here

            // first we create an instance of the grocery class

            Groceries GroceryList = new Groceries();

            // then call the method to fill it with groceries

            TestClass.AddGroceries(GroceryList);

            // below we use a delegate to cycle through the list and print each grocery item

            Console.WriteLine("Grocery List: ");
            Console.WriteLine();

            GroceryList.ProcessItems(new ProcessDelegate(PrintList));

            // next we instantiate a test class object so we can find use the other methods we defined 

            TestClass Test = new TestClass();

            // now we use a delegate to first find and return the highest priced item

            GroceryList.ProcessItems(new ProcessDelegate(Test.FindHighestPrice));
            Test.ReturnHighestPrice();

            // and lastly we use a delegate to find and return the sum of all items on the list

            GroceryList.ProcessItems(new ProcessDelegate(Test.FindTotalPrice));
            Test.ReturnTotalPrice();



            //Wait for user to acknowledge result
            Console.WriteLine("Press Enter to terminate...");
            Console.Read();
        }
Example #2
0
        // here we define a last method to fill the list with groceries

        static void AddGroceries(Groceries GroceryList)
        {
            GroceryList.AddItem("Apple", 0.55m);
            GroceryList.AddItem("Bread", 2.55m);
            GroceryList.AddItem("Orange Juice", 3.20m);
            GroceryList.AddItem("Banana", 0.40m);
            GroceryList.AddItem("Milk", 3.60m);
            GroceryList.AddItem("Eggs", 2.80m);
        }