From 58d04197ee4808afc7834cc78ae8a1776cbce06b Mon Sep 17 00:00:00 2001 From: wook Date: Mon, 3 Apr 2017 03:04:41 +0900 Subject: [PATCH] LINQ 3 --- .../Controllers/HomeController.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/LanguageFeatures/Controllers/HomeController.cs b/LanguageFeatures/Controllers/HomeController.cs index 2487b44..a1f341b 100644 --- a/LanguageFeatures/Controllers/HomeController.cs +++ b/LanguageFeatures/Controllers/HomeController.cs @@ -143,5 +143,22 @@ namespace LanguageFeatures.Controllers return View("Result", (object)result.ToString()); } - } + + public ViewResult SumProducts() + { + Product[] products = + { + 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 = "Coner flag", Category = "Soccer", Price = 34.95M } + }; + + var results = products.Sum(e => e.Price); + + products[2] = new Product { Name = "Stadium", Price = 7950M }; + + return View("Result", (object)String.Format("Sum: {0:c}", results)); + } + } } \ No newline at end of file