foreach (DictionaryEntry item in second) { first[item.Key] = item.Value; }
If necessary, you can turn this into an extension method (provided that you are using .NET 3.5 or later).
Hashtable one = GetHashtableFromSomewhere(); Hashtable two = GetAnotherHashtableFromSomewhere(); one.UpdateWith(two); // ... public static class HashtableExtensions { public static void UpdateWith(this Hashtable first, Hashtable second) { foreach (DictionaryEntry item in second) { first[item.Key] = item.Value; } } }
Lukeh
source share