Remove duplicates from List(Of T)

后端 未结 3 556
北海茫月
北海茫月 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: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
    

提交回复
热议问题