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,900 questions

51,831 answers

573 users

How to delete duplicate elements from one dimensional array of integers in VB.NET

3 Answers

0 votes
Module Module1

    Sub Main()

        Dim arr() As Integer = {1, 2, 3, 2, 5, 6, 6, 2}
        Dim list As New List(Of Integer)

        For Each n In arr
            If Not (list.Contains(n)) Then list.Add(n)
        Next

        arr = list.ToArray()

        For i As Integer = 0 To arr.Length - 1
            Console.Write("{0,3}", arr(i))
        Next

    End Sub

End Module

'run:
'
'  1  2  3  5  6

 



answered Feb 12, 2016 by avibootz
edited Feb 17, 2016 by avibootz
0 votes
Module Module1

    Sub Main()

        Dim arr() As Integer = {1, 2, 3, 2, 5, 6, 6, 2}

        arr = arr.Distinct().ToArray()

        For i As Integer = 0 To arr.Length - 1
            Console.Write("{0,3}", arr(i))
        Next

    End Sub

End Module

'run:
'
'  1  2  3  5  6

 



answered Feb 12, 2016 by avibootz
edited Feb 17, 2016 by avibootz
0 votes
Module Module1

    Sub Main()

        Dim arr() As Integer = {1, 2, 3, 2, 5, 6, 6, 2}
        Dim i As Integer, j As Integer, k As Integer, size As Integer

        size = arr.Length

        For i = 0 To size - 1
            For j = i + 1 To size - 1
                If (arr(j) = arr(i)) Then
                    For k = j To size - 2
                        arr(k) = arr(k + 1)
                    Next
                    size -= 1
                    arr(k) = 0
                    j -= 1
                End If
            Next
        Next

        For i = 0 To size - 1
            Console.Write("{0,3}", arr(i))
        Next

    End Sub

End Module

'run:
'
'  1  2  3  5  6

 



answered Feb 12, 2016 by avibootz
edited Feb 17, 2016 by avibootz
...