HashSet(T).SymmetricExceptWith Method keeps elements that are present either in that object or in the specified collection, but not both.
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
lowNumbers.SymmetricExceptWith(highNumbers)
Console.Write("lowNumbers contains {0} elements: ", lowNumbers.Count)
End Sub
End Class
Related examples in the same category