【发布时间】:2019-06-23 19:00:20
【问题描述】:
我有两个列表,一个是字符串列表,另一个是称为“ItemTransactions”的复杂类型列表。
第一个列表包含 ItemID 的列表,并且基于该第一个列表,无论“ItemTransactinos”列表中的 ItemID 出现在何处,都必须将其删除...
按照以下传统方式进行操作非常慢,因为两个列表都很大:
foreach (var item in ItemIDs) // ItemIDs is lsit of strings
{
itemTransactions.Remove(/*remove*/); // 1 itemID can occur multiple times in this list... So I would like to remove all items in this collections that correspond 1 ItemID at once if possible?
}
有人可以帮我解决这个问题吗?
附: ItemTransactions 集合包含名为“ItemID”的属性,它也是字符串类型......请注意
【问题讨论】:
-
所以问题是性能,您正在寻找有关如何优化的建议?您可能想要包含一个 MVCE 和一个示例数据集。
-
@ChrisPickford 是的,而且基本上如何一次删除属于 1 个 ItemID 的多个事务......我不知道如何以有效的方式完成,因为两个列表都可以相当大吗?
-
你就不能根据
ItemList.Where(i => !StringList.Contains(i.ItemID)做点什么吗? -
@nalka 最终产品需要是没有来自 ItemID 列表的所有 itemid 的列表(复杂类型):D
-
@nalka 但好点:D
标签: c# asp.net-mvc list asp.net-mvc-4 removeall