【发布时间】:2013-07-02 09:07:58
【问题描述】:
如果我有这样的课程:
public class Foo
{
public string Category {get;set;}
public IEnumerable<Bar> Bars {get;set};
}
我有一个这样的 Foos 集合:
foo1: { Category = "Amazing", Bars = /* some Bars */ }
foo2: { Category = "Amazing", Bars = /* some Bars */ }
foo3: { Category = "Extraordinary", Bars = /* some Bars */ }
我如何将它聚合成一个新的 2 个 Foo 集合,如下所示:
foo4: { Category = "Amazing", Bars = /* all the Bars from foo1 and foo2 because both of them have the category "Amazing" */ }
foo5: { Category = "Extraordinary", Bars = /* some Bars */ }
抱歉,如果我没有用正确的语言解释这一点。 Linq 中的聚合每次都让我失望。
谢谢。
【问题讨论】:
标签: c# linq aggregation