How to get the unique values of an array in VB.NET

2 Answers

0 votes
Imports System
Imports System.Linq

Public Class UniqueValuesOfAnArray
    Public Shared Sub Main(ByVal args As String())
        Dim arr As Integer() = {1, 2, 1, 1, 3, 3, 4, 4, 5, 5, 5, 5, 6, 7, 7, 8}

        Dim result = (From n In arr Select n).Distinct()

        For Each val In result
            Console.Write(val & " ")
        Next
    End Sub
End Class



' run:
'
' 1 2 3 4 5 6 7 8 
'

 



answered Feb 16, 2025 by avibootz
0 votes
Imports System
Imports System.Linq

Public Class UniqueValuesOfAnArray
    Public Shared Sub Main(ByVal args As String())
        Dim arr As Integer() = {1, 2, 1, 1, 3, 3, 4, 4, 5, 5, 5, 5, 6, 7, 7, 8}

        Dim result = arr.Distinct().ToArray()

        For Each val In result
            Console.Write(val & " ")
        Next
    End Sub
End Class



' run:
'
' 1 2 3 4 5 6 7 8 
'

 



answered Feb 16, 2025 by avibootz
...