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 }
|
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,4 +1,4 @@
|
|||||||
@Model String
|
|
||||||
@{
|
@{
|
||||||
Layout = null;
|
Layout = null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user