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

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to initialize a HashSet from an array in VB.NET

2 Answers

0 votes
Imports System
Imports System.Collections.Generic

Public Class Program
    Public Shared Sub addToSet(ByVal arr As Integer(), ByVal hset As HashSet(Of Integer))
        For i As Integer = 0 To arr.Length - 1
            hset.Add(arr(i))
        Next
    End Sub

    Public Shared Sub Main()
        Dim arr As Integer() = {1, 5, 7, 3, 9, 8, 0, 2}
        Dim hset As HashSet(Of Integer) = New HashSet(Of Integer)()
	
        addToSet(arr, hset)

        For Each item In hset
            Console.Write(item & " ")
        Next
    End Sub
End Class






' run:
'
' 1 5 7 3 9 8 0 2
'

 





answered Dec 6, 2021 by avibootz
0 votes
Imports System
Imports System.Collections.Generic

Public Class Program
	Public Shared Sub Main()
        Dim arr As Integer() = {4, 6, 12, 3, 100, 99, 7, 0, 1}

        Dim hashset = New HashSet(Of Integer)(arr)

        For Each item In hashset
            Console.Write(item & " ")
        Next
    End Sub
End Class







' run:
'
' 4 6 12 3 100 99 7 0 1
'

 





answered Dec 6, 2021 by avibootz

Related questions

1 answer 55 views
55 views asked Jul 18, 2022 by avibootz
2 answers 59 views
1 answer 54 views
1 answer 168 views
1 answer 25 views
25 views asked Mar 9, 2023 by avibootz
...