Remove duplicates from List(Of T)
<p>How can I remove my duplicates in the <code>List(Of String)</code>? I was under the assumption that it could work with <code>List(Of T).Distinct</code>, but my result says otherwise. What am I doing wrong? Or what do I have to change to remove the duplicate items in the <code>List(Of T)</code>?</p>

<p>I have read something on the worldwide web about hash something, but I don't think that is really necessary.</p>

<p>This is my code where the list is generated (works with Autodesk Inventor).</p>

<pre><code>Private Function CountCylinders(ByVal oDef As AssemblyComponentDefinition) As Integer

    ' Lets list all cylinder segments found in the assembly
    ' we will need the document name to do this.
    ' the initial value is nothing, if, after counting
    ' this is still the case, there are no cylinders.
    Dim oList As New List(Of String)

    ' Loop through all of the occurences found in the assembly
    For Each oOccurrence As ComponentOccurrence In oDef.Occurrences

        ' Get the occurence document
        Dim oOccurenceDocument As Document
        oOccurenceDocument = oOccurrence.Definition.Document

        ' Check if the occurence document name contains cylinder
        If oOccurenceDocument.FullFileName.Contains("Cylinder") Then
            ' Get the cylinder filename
            Dim oCylinder As String
            oCylinder = oOccurenceDocument.FullFileName

            ' Get the filename w/o extension
            oCylinder = IO.Path.GetFileNameWithoutExtension(oCylinder)

            ' Remove the segment mark.
            oCylinder = oCylinder.Remove(oCylinder.LastIndexOf("_"), oCylinder.Length - oCylinder.LastIndexOf("_"))

            oList.Add(oCylinder)
            Debug.Print("add : " &amp; oCylinder)
        End If
    Next

    ' Delete the duplicates in the list
    oList.Distinct()

    ' TODO: can be removed.
    Debug.Print("Total number of cylinders = " &amp; oList.Count)

    ' Return the number of cylinders
    CountCylinders = oList.Count

End Function
</code></pre>

<p>Here is my debug output from the code:</p>

<pre><code>add : Cylinder_1
add : Cylinder_2
add : Cylinder_2
add : Cylinder_2
add : Cylinder_2
add : Cylinder_2
add : Cylinder_7
Total number of cylinders = 7
</code></pre>