Solved

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

Posted on 2013-12-19
2
330 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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:…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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