C# .NET 3.5:如何使用3.5函数从列表中删除

C# .NET 3.5:如何使用3.5函数从列表中删除,c#,.net-3.5,C#,.net 3.5,我有一个对象列表。每个对象都有一个ID。我想删除其ID出现在给定集合中的所有对象。 我知道在3.5中有一些函数,比如RemoveAll,可以帮助搜索和删除 该功能的原型是: internal SomeObject removeFromMe(Dictionary<string, string> idsToRemoveAreTheKeys) internal SomeObject remove fromme(字典ID存储移动键) 从列表中删除的最佳方式是什么? 谢谢 这将检查列表中的

我有一个对象列表。每个对象都有一个ID。我想删除其ID出现在给定集合中的所有对象。 我知道在3.5中有一些函数,比如RemoveAll,可以帮助搜索和删除

该功能的原型是:

internal SomeObject removeFromMe(Dictionary<string, string> idsToRemoveAreTheKeys)
internal SomeObject remove fromme(字典ID存储移动键)
从列表中删除的最佳方式是什么?
谢谢

这将检查列表中的每个项目一次,并在字典中执行键查找,因此大约为O(N),因为键查找很快


如果循环遍历键,则每次都必须在列表中进行线性搜索,这需要O(N*M),其中M是字典中的键数。

对于列表,可以执行以下操作:

    Dim sam As New List(Of Integer) From {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    sam.RemoveAll(Function(x) x Mod 2 = 0)

    var sam = New List<int> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    sam.RemoveAll( x => x % 2 = 0)
Dim sam作为来自{1,2,3,4,5,6,7,8,9,10}的新列表(整数)
sam.RemoveAll(函数(x)x Mod 2=0)
var sam=新列表{1,2,3,4,5,6,7,8,9,10}
sam.RemoveAll(x=>x%2=0)
    Dim sam As New List(Of Integer) From {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    sam.RemoveAll(Function(x) x Mod 2 = 0)

    var sam = New List<int> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    sam.RemoveAll( x => x % 2 = 0)