查看两个列表中匹配的项目
以免说我有两个列表
List1:
“Tom”, “坦率”, “莱西”
名单2:
“弗兰克”, “Tom”
需要什么查询才能显示 Tom 和 Fran 被重复?
我想要比较的列表非常大,如果我执行以下操作:
var q = from a in List1
from b in List2
where a.Name == b.Name
select a;
这需要很长时间。
lest say I have two lists
List1:
"Tom",
"Frank",
"Lacey"
List2:
"Frank",
"Tom"
what would be the query needed to show that Tom and Fran are being repeated?
The lists that I am trying to compare are very big and if I do something like:
var q = from a in List1
from b in List2
where a.Name == b.Name
select a;
this takes a long time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要查看哪些值在列表中重复,您可以使用
如果您对匹配项目并对每个项目执行某些操作感兴趣,您可以使用
Join
在您的情况下,因为您正在处理一个列表对于字符串,
Intersect
似乎是合适的操作过程。如果您正在处理公共键上的匹配对象列表,您可能会选择加入列表并投影结果。To see what values are duplicated across lists, you can use
If you were otherwise interested in matching the items and doing something with each, you could use
Join
In your case, since you are dealing with a list of strings,
Intersect
seems like the appropriate course of action. If you were dealing with matching lists of objects on a common key, you might opt to join the lists and project the results.您应该使用Intersect:
You should use Intersect:
您可以使用相交:
You can use intersect: