HashSet(T).ExceptWith Method removes all elements in the specified collection from the current HashSet(Of T) object.
Imports System
Imports System.Collections.Generic
Class Program
Shared Sub Main()
Dim lowNumbers As HashSet(Of Integer) = New HashSet(Of Integer)()
Dim highNumbers As HashSet(Of Integer) = New HashSet(Of Integer)()
For i As Integer = 0 To 5
lowNumbers.Add(i)
Next i
For i As Integer = 3 To 9
highNumbers.Add(i)
Next i
Console.Write("lowNumbers contains {0} elements: ", lowNumbers.Count)
Console.Write("highNumbers contains {0} elements: ", highNumbers.Count)
highNumbers.ExceptWith(lowNumbers)
Console.Write("highNumbers contains {0} elements: ", highNumbers.Count)
End Sub
End Class
Related examples in the same category