My class:
public class Foo
{
public int A { get; set; }
public List<Bar> Bars { get; set; }
}
I’ve got IEnumerable<Foo>. I would like get List<Foo> grouping by A, and get Bars list, which contais all elements at Bars for group.
So final Foo.Bars should contains all elements of Bar at group
Is it possible with linq?
As Rawling has mentioned, this returns not an
IEnumerable<Foo>, so try this:I’m not sure whether you want a distinct list of
Barsor not. Note that you may need to overrideEqualsandGetHashCodein classBar.