Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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