我一直在使用101 LINQ Samples让我的脚使用LINQ湿。这是一个很好的第一资源,但我看不到我目前需要的一个例子。组号的LINQ集团按查询
我只需要将一个连续的组号码与每个组相关联。我有一个工作解决方案:
var groups =
from c in list
group c by c.Name into details
select new { Name = details.Key, DetailRecords = details };
int groupNumber = 0;
foreach (var group in groups)
{
//
// process each group and it's records ...
//
groupNumber++;
}
但是,我敢肯定有可能使用LINQ来生成groupNumber。怎么样?
嘿,聪明。我喜欢。 – 2010-07-19 17:17:06
+1 ... clever =) – Luiscencio 2010-07-19 17:18:23
这里有两个答案。我喜欢ToList解决方案,但两个参数选择正是我所期待的。非常感谢。 – 2010-07-19 17:46:24