如何从一个列表中删除另一个列表中的所有项目? [英] How to remove from one list all the items in another?
本文介绍了如何从一个列表中删除另一个列表中的所有项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从远程数据库中读取一组行,并从本地数据库中读取一组类似的行,然后使用RemoveAll摆脱本地已经存在的远程行...
I'm reading a set of rows from a remote database, and a similar set from a local database, and then using RemoveAll to get rid of remote rows that are already present locally...
remote_events = (From a In remote.Events
Where ...etc...).ToList
local_events = (From a In local.Events
Where ...etc...).ToList
remote_events.RemoveAll(Function (ByVal event_row As Remote_Event)
(From a In local_events Where a.Identifier = event_row.Identifier).Count > 0)
但这对我来说似乎不正确.当我真正需要做的只是检查是否存在匹配项时,我认为我不应该在计算任何事情.我已经尝试了IsDBNull
和IsNothing
的各种用法,但是胡说八道.我无法使用.Except
(如建议的此处),因为列表元素不是同一类型.
but this doesn't seem right to me. I don't think I should be counting things when all I really need to do is check whether a match exists. I've tried various usages of IsDBNull
and IsNothing
but get nonsense. I can't use .Except
(as suggested here) because the list elements are not the same type.
有更好的方法吗?
推荐答案
一种方法是
remote_events.RemoveAll(Function(e) local_events.Exists(Function(f) f.Identifier = e.Identifier))
这篇关于如何从一个列表中删除另一个列表中的所有项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文