I have a list of Foo
. Foo has properties Bar
and Lum
. Some Foo
s have identical values for Bar
. How can I use lambda/linq to group my Foo
s by Bar
so I can iterate over each grouping's Lum
s?
var q = from x in list
group x by x.Bar into g
select g;
foreach (var group in q)
{
Console.WriteLine("Group " + group.Key);
foreach (var item in group)
{
Console.WriteLine(item.Bar);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With