Skip to content

Instantly share code, notes, and snippets.

@xinmyname
Last active August 29, 2015 14:25
Show Gist options
  • Save xinmyname/7f3a9415cd0a965ef342 to your computer and use it in GitHub Desktop.
Save xinmyname/7f3a9415cd0a965ef342 to your computer and use it in GitHub Desktop.
C# Set Diffs
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