Remove duplicates from List(Of T)

后端 未结 3 485
北海茫月
北海茫月 2021-01-20 17:47

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

相关标签:
3条回答
  • 2021-01-20 18:09

    This is the answer you're looking for thanks to dotnetperls.com VB.NET Remove Duplicates From List

    ListOfString.Distinct().ToList
    
    0 讨论(0)
  • 2021-01-20 18:13
    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
    
    0 讨论(0)
  • 2021-01-20 18:22
    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.

    0 讨论(0)
提交回复
热议问题