Solved

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

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

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

20 Experts available now in Live!

Get 1:1 Help Now