VB.Net - Hashset allows duplicates

Hi Experts.   Can some one please explain why my hashset allows duplicates.  If I test the contents of the folder and the hashset, they are the same but I know there are duplicates.  I thought hashsets did not allow duplicates
      
        Dim files = Directory.EnumerateFiles(Path, "*.*", SearchOption.AllDirectories)
         
        Dim myHashSet1 As New HashSet(Of String)
            For Each f In files
                If (myHashSet1.Add(f)) Then
                    'do nothing
                Else
                    'do something
                End If
            Next
LVL 2
PNRTAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
If you have two or more files with the same names but in different directories then they are NOT the same and therefore will not cause a issue to add them to the HashSet. And because you can not have two files in the same directory with the same name I think this is what is happening.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AndyAinscowFreelance programmer / ConsultantCommented:
>>If I test the contents of the folder and the hashset, they are the same but I know there are duplicates.

How do you test for duplicates?
What is, in your opinion, a duplicate?  (Two files, one an exact copy of the other: a.txt and copy of a.txt - duplicate, to the user yes, to the hashset no.)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.