Created
May 1, 2012 21:16
-
-
Save josheinstein/2571458 to your computer and use it in GitHub Desktop.
Testing sets for equality (IEnumerable and IDictionary)
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; | |
public static class CollectionHelper { | |
public static bool SetsEqual(IEnumerable set1, IEnumerable set2) { | |
var h1 = new Hashtable(); | |
foreach ( var item in set1 ) { | |
h1[item] = true; | |
} | |
foreach ( var item in set2 ) { | |
if ( !h1.Contains(item)) { | |
return false; | |
} | |
} | |
return true; | |
} | |
public static bool SetsEqual(IDictionary h1, IDictionary h2) { | |
if (h1.Count != h2.Count) { | |
return false; | |
} | |
foreach ( object key in h1.Keys ) { | |
if (!Object.Equals(h1[key], h2[key])) { | |
return false; | |
} | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment