How can I update the values of one hashtable by another hashtable,
if second hashtable contains new keys then they must be added to 1st else should update the value of 1st hashtable.
foreach (DictionaryEntry item in second)
{
first[item.Key] = item.Value;
}
If required you could roll this into an extension method (assuming that you're using .NET 3.5 or newer).
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;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With