Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,845 questions

51,766 answers

573 users

How to remove duplicates from a list in VB.NET

2 Answers

0 votes
Imports System
Imports System.Linq
Imports System.Collections.Generic

Public Class Program
	Public Shared Sub Main()
        Dim list = New List(Of Integer)() From { 2, 4, 4, 9, 7, 3, 4, 6, 0, 3 }
        
		list = list.Distinct().ToList()
        
		Console.WriteLine(String.Join(" ", list))
    End Sub
End Class




' run:
'
' 2 4 9 7 3 6 0
'

 



answered Mar 19, 2023 by avibootz
0 votes
Imports System
Imports System.Collections.Generic

Public Class Program
    Public Shared Function RemoveDuplicates(ByVal list As List(Of String)) As List(Of String)
        Dim result = New List(Of String)()
        Dim _set = New HashSet(Of String)()

        For i As Integer = 0 To list.Count - 1
            If Not _set.Contains(list(i)) Then
                result.Add(list(i))
                _set.Add(list(i))
            End If
        Next

        Return result
    End Function

    Public Shared Sub Main()
        Dim list = New List(Of String)() From { "a", "b", "b", "a", "c", "b", "b", "c", "c", "d" }
        
		list = RemoveDuplicates(list)
    	    
		Console.WriteLine(String.Join(" ", list))
    End Sub
End Class





' run:
'
' a b c d
'

 



answered Mar 19, 2023 by avibootz

Related questions

1 answer 54 views
1 answer 174 views
1 answer 147 views
2 answers 100 views
1 answer 89 views
1 answer 149 views
...