If your desired result is a final list of unique items, you could try adding the items from each Dictionary
to a HashSet
, and go from there. I don't know if this is going to be any faster, but it's worth a shot.
You might be able to do this in .Net 2.0 - extension methods (typed off the top of my brain, so you may have to tweak it):
public static class ExtensionMethods
{
public static bool AddUnique(this Dictionary<T, T> dict, object key, object value)
{
bool added = true;
if (this.Contains(key))
{
added = false;
this[key].Value = value;
}
else
{
this.Add(key, value);
}
return added;
}
public static bool AddUnique(this Dictionary<T, T> dict, KeyValuePair<T, T> kvp)
{
return dict.AddUnique(kvp.Key, kvp.Value);
}
EDIT #2 =============
You can do extension methods in.Net 2.0, but you have to define your own attribute:
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class ExtensionAttribute : Attribute
{
}
}
And then add the attribute to each of your extension methods.