1
0
mirror of https://github.com/rudollee/LearningMVC.git synced 2026-08-11 16:32:55 +00:00

LINQ Another

This commit is contained in:
wook
2017-04-03 03:01:07 +09:00
parent 7868a902d7
commit 496c391fd0
2 changed files with 13 additions and 8 deletions
+12 -7
View File
@@ -121,19 +121,24 @@ namespace LanguageFeatures.Controllers
new Product {Name = "Coner flag", Category = "Soccer", Price = 34.95M } new Product {Name = "Coner flag", Category = "Soccer", Price = 34.95M }
}; };
var FoundProducts = from match in products //var FoundProducts = from match in products
orderby match.Price descending // orderby match.Price descending
select new { match.Name, match.Price }; // 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; int count = 0;
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
foreach (var p in FoundProducts) foreach (var p in FoundProducts)
{ {
result.AppendFormat("Price: {0} ", p.Price); result.AppendFormat("Price: {0} ", p.Price);
if (++count == 3) //result.AppendFormat("Price: {0} ", p.Price);
{ //if (++count == 3)
break; //{
} // break;
//}
} }
return View("Result", (object)result.ToString()); return View("Result", (object)result.ToString());
+1 -1
View File
@@ -1,4 +1,4 @@
@Model String
@{ @{
Layout = null; Layout = null;
} }