我有一个扩展方法可以方便地进行左外部连接:
public static IEnumerable<TResult> LeftOuterJoin<TLeft, TRight, TKey, TResult>(
this IEnumerable<TLeft> leftSeq,
IEnumerable<TRight> rightSeq,
Func<TLeft, TKey> keySelectorLeft,
Func<TRight, TKey> keySelectorRight,
Func<TLeft, TRight, TResult> projectionSelector)
{
return leftSeq
.GroupJoin(
rightSeq,
keySelectorLeft,
keySelectorRight,
(leftItem, rightItems) => new { leftItem, rightItems })
.SelectMany(
x => x.rightItems.DefaultIfEmpty(),
(x, rightItem) => projectionSelector(x.leftItem, rightItem));
}
现在我们可以:
tuples.LeftOuterJoin(list, t => t.Symbol, k => k.Symbol, (t,k) => (t,k))
.Where(x => x.k == null)
.Select(x => x.t)
…这将为我们提供tuple列表中的所有项
Symbol
属性,该属性在另一个列表中没有具有相同项的对应项
符号
。对吗?