How can I remove my duplicates in the List(Of String)
? I was under the assumption that it could work with List(Of T).Distinct
, but my result says o
This is the answer you're looking for thanks to dotnetperls.com VB.NET Remove Duplicates From List
ListOfString.Distinct().ToList
Function RemoveDuplicate(ByVal TheList As List(Of String)) As List(Of String)
Dim Result As New List(Of String)
Dim Exist As Boolean = False
For Each ElementString As String In TheList
Exist = False
For Each ElementStringInResult As String In Result
If ElementString = ElementStringInResult Then
Exist = True
Exit For
End If
Next
If Not Exist Then
Result.Add(ElementString)
End If
Next
Return Result
End Function
Imports System.Linq
...
Dim oList As New List(Of String)
oList.Add("My Cylinder")
oList = oList.Distinct.ToList()
It's necessary to include System.Linq
.