Solved

compare 2 hashsets and list the differance in each one with visual basic .net

Posted on 2013-12-19
2
323 Views
Last Modified: 2016-02-10
I have 2 hashset (of string) and would like to compare them.  I would like see what was added/missing in the second set.

hashset1 comare to hashset2
0
Comment
Question by:chadmanvb
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39730215
If you have the LINQ namespace at your disposal, then you can use the Except extension method for this purpose. Here's an example:

Imports System.Linq

Module Module1

    Sub Main()
        Dim firstHashSet As New HashSet(Of String)
        Dim secondHashSet As New HashSet(Of String)

        firstHashSet.Add("one")
        firstHashSet.Add("two")

        secondHashSet.Add("three")
        secondHashSet.Add("one")

        Dim removedFromSecond = firstHashSet.Except(secondHashSet)
        Dim addedToSecond = secondHashSet.Except(firstHashSet)

        For Each item In removedFromSecond 
            Console.WriteLine(item)
        Next

        Console.WriteLine()

        For Each item In addedToSecond 
            Console.WriteLine(item)
        Next

        Console.ReadKey()
    End Sub

End Module

Open in new window

0
 

Author Closing Comment

by:chadmanvb
ID: 39730448
Perfect!  Works great!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now