Holen Sie sich gruppiert, die durch Trennzeichen getrennte Werte mit linq

Möchte ich eine Dritte Spalte "Artikel" mit den Werten, die gruppiert sind.

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();

Dieser code führt zu:

Key Count
1   2
2   1
3   1

Möchte ich diese Ergebnisse:

Key Count Items
1   2     a, b
2   1     c
3   1     d

InformationsquelleAutor Micah B. | 2010-07-13

Schreibe einen Kommentar