I ve got two data category, Foo
and Bar
, which have a property to establish order:
class Foo
{
public int Order { get; set; }
public string FooValue { get; set; }
}
class Bar
{
public int Order { get; set; }
public string BarValue { get; set; }
}
然后,我收到两卷此类资料。 我也希望参加收集工作,这样,结果将包含<代码>的配对。 Foo和Bar
。 奶制品的数量应为<条码> /条码>。
Each pair should consist of a Bar
element and the most "recent" Foo
element (with largest Foo Order
value, bounded by the current Bar Order
value).
例如,在以下汇编中(一些发言略去):
var foos = new [] { (1, "Foo1"), (2, "Foo2"), (5, "Foo5"), (7, "Foo7") };
var bars = new [] { (1, "Bar1"), (6, "Bar6") };
结果是:
result = {
((1, "Bar1"), (1, "Foo1")),
((6, "Bar6"), (5, "Foo5"))
};
我如何用LINQ和C# 4.0来做到这一点?