Removing Duplicates from List Collection

Sounds really simple to pull duplicates out of a list ... MS handled this with a function in VS 3.5 but in earlier versions we had to come up with our own solution.
 

Dim i As Integer
Dim lastapprover As String = String.Empty
Dim iIndex As Integer
iIndex = bulletApprovers.Items.Count

For i = 0 To bulletApprovers.Items.Count - 1
While iIndex > 0
         
If bulletApprovers.Items(i).Text = lastapprover Then
              
lastapprover = bulletApprovers.Items(iIndex).Text
               bulletApprovers.Items.RemoveAt(iIndex)
Else
             
lastapprover = bulletApprovers.Items(iIndex - 1).Text
End If      
          
iIndex = iIndex - 1
End While

Next

Comments

Popular posts from this blog

Linq Exclude from separate list

Sorting Ascending and Descending

Linq Query Syntax vs Method Syntax