[英]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.