1
0
mirror of https://github.com/rudollee/LearningMVC.git synced 2025-06-07 16:06:21 +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

View File

@ -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());

View File

@ -1,4 +1,4 @@
@Model String

@{
Layout = null;
}