<an*******@discussions.microsoft.com> schrieb:
How do I remove duplicates from an arraylist?
Very quick and dirty (the first occurance of each item will remain in the
list):
\\\
Dim al As New ArrayList()
al.AddRange(New String() {"Bla", "Foo", "Foo", "Goo", "Bla", "Baz"})
Dim ht As New Hashtable()
Dim ItemsToRemove As New ArrayList()
Dim Item As String
Dim i As Integer
For i = 0 To al.Count - 1
Item = al(i)
If ht.Contains(Item) Then
ItemsToRemove.Add(i)
Else
ht.Add(Item, Nothing)
End If
Next i
For i = ItemsToRemove.Count - 1 To 0 Step -1
al.RemoveAt(ItemsToRemove(i))
Next i
For i = 0 To al.Count - 1
MsgBox(al(i))
Next i
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>