繁体   English   中英

如何在Linq加入后获得“剩余”记录

[英]How to get the “leftover” records after a Linq Join

我使用一些标准将两个对象列表加入到一个新列表中。 在加入之后,什么是让剩余项目不在加入中的最佳方法?

//line is an internal object, not important here
List<Line> main = ReadMainLines(); //read the main lines
List<Line> ref = ReadReferenceLines(); //read the lines that contain addtional data

IEnumerable<Line[]> result = main.Join(...);

到目前为止,我很好。 我正在使用结果进行一些额外的处理。 我的挑战是从主要部分得到其余部分,而不是在连接结果中。 最好的方法是什么?

如果你想要的是ref ,但不是main ,你可以使用.Except所看到这里

ref.Except(main) - 如果你想要相反,那么它只是main.Except(ref) 现在,您需要为Line类型编写IEquatableComparer

另外,不要将ref用作变量名,它是C#中的关键字。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM