Intersect SortedSet to keep elements that are present either collection, but not both in CSharp
Description
The following code shows how to intersect SortedSet to keep elements that are present either collection, but not both.
Example
using System;/* ww w. ja v a 2 s . co m*/
using System.Collections;
using System.Collections.Generic;
using System.IO;
class Program
{
static void Main(string[] args)
{
SortedSet<string> set1 = new SortedSet<string>();
set1.Add("a");
set1.Add("b");
set1.Add("d");
set1.Add("d");
set1.Add("x");
SortedSet<string> set2 = new SortedSet<string>();
set2.Add("a");
set2.Add("b");
set2.Add("c");
set2.Add("d");
set2.Add("y");
set1.SymmetricExceptWith(set2);
foreach (string s in set1)
{
Console.WriteLine(s);
}
}
}
The code above generates the following result.