Monday, October 26, 2009

Remove duplicates from array-Vb.net

Public Function removeDup(ByVal arrShpLn As ArrayList) As ArrayList
arrShpLn.Sort()
Dim arrShpCopy = arrShpLn.Clone()
Dim count As Integer = arrShpCopy.Count
Dim i As Integer
For i = count - 1 To 1 Step -1
If (arrShpCopy(i).ToString() = arrShpCopy(i - 1).ToString()) Then
arrShpCopy.RemoveAt(i)
End If
Next i

Return arrShpCopy

End Function