When comparing two key-value dictionary sets in C#: set A and set B, what is the best way to enumerate keys present in set A but missing from set B and vice-versa?
For example:
A = { 1, 2, 5 }
B = { 2, 3, 5 }
Comparing B with A, missing keys = { 1 } and new keys = { 3 }.
Using Dictionary<...,...> objects, one can enumerating all values in B and test against set A using A.ContainsKey(key);, but it feels like there should be a better way that might involve a sorted set?
I’m aware of two built-in ways of doing set differences.
1) Enumerable.Except
Example:
2a) HashSet<T>.ExceptWith
2b) HashSet<T>.SymmetricExceptWith
If you need something more performant, you’ll probably need to roll your own collection type.