在2列表vb.net中查找不同的项目 [英] Finding different items in 2 list vb.net

查看:75
本文介绍了在2列表vb.net中查找不同的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个列表,集合类型是我的,它可以是arraylist或hashtable等。这两个列表组成guid的。我需要找到在List-2中不存在的List-1的项。

I have 2 lists, collection type is up to me, it can be arraylist or hashtable etc. Both lists consist guid's. I need to find the items of List-1 which doesnt exists in List-2.

列表可以包含 100万项目。

我使用hashtable方法,但速度很慢。

I used hashtable approach but it is slow.

有更好的方法吗? p>

Is there a better way to achieve that?

推荐答案

您可以使用 Hashset(of T),并使用方法外。

You can use Hashset(of T) and use the Except method. This will return all the items that are in hashset one but not in hashset two.

    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

这篇关于在2列表vb.net中查找不同的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆