Hallo,
wie kann ich aus einem IEnumerable<IGrouping<string, Item> ein IEnumerable<string, Item>.
Garnicht, denn IEnumerable hat nur einen generischen Parameter.
Desweiteren: Warum? Ein IGrouping ist ja ne 1:N Auflösung, d.h. selbst mit nem Dictionary kommst du nicht weiter, da dann ja auf ein key mehrere values kämen.
Hallo daniel94ever
Meinst du sowas:
List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>();
list.Add(new KeyValuePair<string, int>("a", 1));
list.Add(new KeyValuePair<string, int>("a", 2));
list.Add(new KeyValuePair<string, int>("b", 3));
list.Add(new KeyValuePair<string, int>("c", 4));
// group
var result1 = from kvp in list
group kvp by kvp.Key into g
select g;
foreach (var g in result1)
{
Console.WriteLine("Group: {0}", g.Key);
g.ToList().ForEach(i => Console.WriteLine(" {0}", i.Value));
}
Console.WriteLine();
// resolve group
var result2 = from item in result1.SelectMany(g => g)
select item;
foreach (var item in result2)
{
Console.WriteLine("{0}: {1}", item.Key, item.Value);
}
Grüße
Flo
Blog: Things about Software Architecture, .NET development and SQL Server
Twitter
Google+
Je mehr ich weiß, desto mehr weiß ich was ich noch nicht weiß.