vb.net - 在 2 列表 vb.net 中查找不同的项目

标签 vb.net algorithm collections

我有 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/

相关文章:

vb.net - 我的 For 循环跳过了 IF 语句

c# - 什么是NullReferenceException,如何解决?

algorithm - bentley ottman算法扫线数据结构实现

java - 使用堆栈与仅使用双向链表相比有什么好处

algorithm - 实现一个队列,其中push_rear()、pop_front()和get_min()都是常量时间操作

scala - Scala 2.9 和 Actors 中的并行集合

c# - C# 代码是否比 Visual Basic.NET 代码更快?

windows - 下拉组合框时的工具提示

java - 如何在单个对象中创建多个比较器

java - 理解java的同步集合