Last active
August 29, 2015 14:25
-
-
Save xinmyname/7f3a9415cd0a965ef342 to your computer and use it in GitHub Desktop.
C# Set Diffs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace HashSetTest | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
var curSet = new[] {"A","B","C","D","E"}; | |
var newSet = new[] {"A","D","E","F","G","H"}; | |
var added = new HashSet<string>(newSet); | |
added.ExceptWith(curSet); | |
foreach (var item in added) | |
Console.WriteLine("Added: {0}", item); | |
var removed = new HashSet<string>(curSet); | |
removed.ExceptWith(newSet); | |
foreach (var item in removed) | |
Console.WriteLine("Removed: {0}", item); | |
var unchanged = new HashSet<string>(curSet); | |
unchanged.IntersectWith(newSet); | |
foreach (var item in unchanged) | |
Console.WriteLine("Unchanged: {0}", item); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment