Linq-排除来自不同列表类型的项目 [英] Linq - Excluding items from different list types

查看:87
本文介绍了Linq-排除来自不同列表类型的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以选择列表中另一个列表中没有的项目?例如:

Is there any way to select items in a list that aren't contained in another? For example:

list1 = From t In list1 Where Not list2.Contains(t.column1)

这给了我错误:

Value of type 'Integer' cannot be converted to '<anonymous type>'

这很有意义,因为list2.Contains期望与list2具有相同的类型.但是,列表类型不同.我只想根据列比较进行选择.

which makes sense, since list2.Contains is expecting the same type as list2. However, the list types are different. I want only to select based on column comparisons.

推荐答案

您尝试过这种方法吗?

list1 = From t In list1 Where Not list2.Any(l => t.column1 = l.column1 AndAlso t.column2 = l.column2)

我不确定它的效率如何,但我认为它应该对您有用.

I am unsure how efficient it would be, but I think it should work for you.

这篇关于Linq-排除来自不同列表类型的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆