# exclusive $copy = New-Object System.Collections.Generic.HashSet[string] $set1 $copy.ExceptWith($set2) "Exclusive in Set 1" "$copy"
# exclusive either side $copy = New-Object System.Collections.Generic.HashSet[string] $set1 $copy.SymmetricExceptWith($set2) "Exclusive in both (no duplicates)" "$copy"
以下是执行结果:
Original Sets:
Harry Mary Terri
Tom Tim Terri Tobias
In Both
Terri
All Combined
Harry Mary Terri Tom Tim Tobias
Exclusive in Set 1
Harry Mary
Exclusive in both (no duplicates)
Harry Mary Tobias Tom Tim
# in both $copy = New-Object'System.Collections.Generic.HashSet[int32]'$set1 $copy.IntersectWith($set2) "In Both" "$copy"
# combine $copy = New-Object'System.Collections.Generic.HashSet[int32]'$set1 $copy.UnionWith($set2) "All Combined" "$copy"
# exclusive $copy = New-Object'System.Collections.Generic.HashSet[int32]'$set1 $copy.ExceptWith($set2) "Exclusive in Set 1" "$copy"
# exclusive either side $copy = New-Object'System.Collections.Generic.HashSet[int32]'$set1 $copy.SymmetricExceptWith($set2) "Exclusive in both (no duplicates)" "$copy"
Original Sets:
1 2 5 7 9 12
1 2 5 12 111
In Both
1 2 5 12
All Combined
1 2 5 7 9 12 111
Exclusive in Set 1
7 9
Exclusive in both (no duplicates)
7 9 111