我有这段代码
var result = from row in DTgraph.AsEnumerable()
group row by row.Field<string>("Campaign") into grp
select new
{
Campaign = grp.Key,
Count = grp.Count(),
SL = grp.Sum(s => s.Field<Decimal>("Inb.ServiceLevel"))
};
DTgraph
是DataTable
我想在result
上制作循环。怎么样?
答案 0 :(得分:2)
您可以使用foreach
:
foreach (var item in result)
{
//Your code here
}
或for
知道索引。但是你必须在LINQ的末尾添加.ToList()
:
var result = (from row in DTgraph.AsEnumerable()
group row by row.Field<string>("Campaign") into grp
select new
{
Campaign = grp.Key,
Count = grp.Count(),
SL = grp.Sum(s => s.Field<Decimal>("Inb.ServiceLevel"))
}).ToList();
for (int i = 0; i < result.Count(); i++)
{
//Your code here
//Now you can do result[i].Something
}
答案 1 :(得分:0)
这是一个循环:
foreach (var item in result)
{
//your logic to each item of loop
}