110,538
社区成员
发帖
与我相关
我的任务
分享
Key,Value
A,1
A,2
A,3
A,4
B,2
B,3
B,5
C,1
C,4
C,5
D,3
.....
List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>();
list.Add(new KeyValuePair<string, int>("A, 1"));
...
var query = list.SelectMany(x => list.Where(y => y.Key > x.Key && y.Value == x.Value).Select(y => new { x, y }))
.GroupBy(x => new { k1 = x.Key, k2 = y.Key })
.Select(x => string.Format("{0},{1} = {2}", x.Key.k1, x.Key.k2, x.Count()));
foreach (string item in query)
Console.WriteLine(item);