mirror of
https://github.com/rudollee/LearningMVC.git
synced 2025-06-07 16:06:21 +00:00
LINQ Another
This commit is contained in:
parent
7868a902d7
commit
496c391fd0
@ -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());
|
||||
|
@ -1,4 +1,4 @@
|
||||
@Model String
|
||||
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user