Beispiel #1
0
        public ViewResult UseFilterExtensionFumMethod()
        {
            //Создать и заполнить обьект shoppingCard
            IEnumerable<Product> products = new ShoppingCart
            {
                Products = new List<Product>
                {
                    new Product
                    {
                        Name = "Kayak",
                        Category = "Watersports",
                        Price = 275M
                    },
                    new Product
                    {
                        Name = "LifeJacket",
                        Category = "Watersports",
                        Price = 48.95M
                    },
                    new Product
                    {
                        Name = "Soccer ball",
                        Category = "Soccer"
                        ,
                        Price = 19.50M
                    },
                    new Product
                    {
                        Name = "Corner flag",
                        Category = "Soccer",
                        Price = 34.95M
                    }
                }
            };
            decimal total = 0;
            //Лямда выражение в foreach
            foreach (var product in products.FilterByLyambda(product =>
                product.Category == "Socer" || product.Price > 20))
            {
                total += product.Price;
            }

            return View("Result", (object) string.Format("Total: {0:c}", total));
        }