HashSet(T) Class Represents a set of values.
Imports System
Imports System.Collections.Generic
Class Program
Shared Sub Main()
Dim evenNumbers As HashSet(Of Integer) = New HashSet(Of Integer)()
Dim oddNumbers As HashSet(Of Integer) = New HashSet(Of Integer)()
For i As Integer = 0 To 4
evenNumbers.Add(i * 2)
oddNumbers.Add((i * 2) + 1)
Next i
Console.Write(evenNumbers.Count)
DisplaySet(evenNumbers)
Console.Write(oddNumbers.Count)
DisplaySet(oddNumbers)
Dim numbers As HashSet(Of Integer) = New HashSet(Of Integer)(evenNumbers)
Console.WriteLine("numbers UnionWith oddNumbers...")
numbers.UnionWith(oddNumbers)
Console.Write("numbers contains {0} elements: ", numbers.Count)
DisplaySet(numbers)
End Sub
Private Shared Sub DisplaySet(ByVal coll As HashSet(Of Integer))
For Each i As Integer In coll
Console.WriteLine(" {0}", i)
Next i
End Sub
End Class
Related examples in the same category