我想要分組的值的第三列「項目」。用linq獲取分組逗號分隔值
Dictionary<string, int> dic = new Dictionary<string, int>();
dic.Add("a", 1);
dic.Add("b", 1);
dic.Add("c", 2);
dic.Add("d", 3);
var dCounts =
(from i in dic
group i by i.Value into g
select new { g.Key, count = g.Count()});
var a = dCounts.Where(c => c.count>1);
dCounts.Dump();
a.Dump();
該代碼產生:
Key Count
1 2
2 1
3 1
我想這些結果:
Key Count Items
1 2 a, b
2 1 c
3 1 d
如果我們使用string.Join,那麼像Linq這樣的異常無法識別string.Join方法 – reddy39 2017-12-01 11:00:40