我有 2 个列表,集合类型由我决定,它可以是 arraylist 或 hashtable 等。两个列表都包含 guid。我需要找到 List-1 中不存在于 List-2 中的项目。
两个列表都可以包含100万项。
我使用哈希表方法,但它很慢。
有没有更好的方法来实现它?
最佳答案
您可以使用 Hashset(of T)并使用 Except方法。这将返回哈希集一中但不在哈希集二中的所有项目。
Dim numbers1() As new HashSet(of Double)({2.0, 2.1, 2.2, 2.3, 2.4, 2.5})
Dim numbers2() As new hashset(of Double)({2.2})
Dim onlyInFirstSet As IEnumerable(Of Double) = numbers1.Except(numbers2)
' This code produces the following output:
'
' 2
' 2.1
' 2.3
' 2.4
' 2.5
关于vb.net - 在 2 列表 vb.net 中查找不同的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16732399/