From 496c391fd0cd126de67ebd17ddc98313b758b338 Mon Sep 17 00:00:00 2001 From: wook Date: Mon, 3 Apr 2017 03:01:07 +0900 Subject: [PATCH] LINQ Another --- .../Controllers/HomeController.cs | 19 ++++++++++++------- LanguageFeatures/Views/Home/Result.cshtml | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/LanguageFeatures/Controllers/HomeController.cs b/LanguageFeatures/Controllers/HomeController.cs index 57aa466..2487b44 100644 --- a/LanguageFeatures/Controllers/HomeController.cs +++ b/LanguageFeatures/Controllers/HomeController.cs @@ -121,19 +121,24 @@ namespace LanguageFeatures.Controllers new Product {Name = "Coner flag", Category = "Soccer", Price = 34.95M } }; - var FoundProducts = from match in products - orderby match.Price descending - select new { match.Name, match.Price }; + //var FoundProducts = from match in products + // orderby match.Price descending + // select new { match.Name, match.Price }; + + var FoundProducts = products.OrderByDescending(e => e.Price).Take(3).Select(e => new { e.Name, e.Price }); + + products[2] = new Product { Name = "Stadium", Price = 79600M }; int count = 0; StringBuilder result = new StringBuilder(); foreach (var p in FoundProducts) { result.AppendFormat("Price: {0} ", p.Price); - if (++count == 3) - { - break; - } + //result.AppendFormat("Price: {0} ", p.Price); + //if (++count == 3) + //{ + // break; + //} } return View("Result", (object)result.ToString()); diff --git a/LanguageFeatures/Views/Home/Result.cshtml b/LanguageFeatures/Views/Home/Result.cshtml index b5dd30c..dc0c1da 100644 --- a/LanguageFeatures/Views/Home/Result.cshtml +++ b/LanguageFeatures/Views/Home/Result.cshtml @@ -1,4 +1,4 @@ -@Model String + @{ Layout = null; }