Solved

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

Posted on 2013-12-19
2
325 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

838 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