コード例 #1
0
        static void Main(string[] args)
        {
            PopulateOrders();

            Console.WriteLine($"The total for the cart is {cart.TotalItems(SubTotalAlert, CalculateLeveledDiscount, AlertUser):C2}");

            Console.WriteLine();

            //creating anonymous delegate - inline code
            decimal total = cart.TotalItems((subTotal) => Console.WriteLine($"The subtotal for cart 2 is {subTotal:C2}"),
                                            (products, subTotal) =>
            {
                if (products.Count > 3)
                {
                    return(subTotal * 0.5M);
                }
                else
                {
                    return(subTotal);
                }
            },
                                            (message) => Console.WriteLine($"Cart 2 alert {message}"));

            Console.WriteLine($"The total for cart2 is {total:C2}");

            Console.WriteLine();
            Console.WriteLine("Press any key to exit the application...");
            Console.ReadKey();
        }