Join / merge C # hash tables

I am in .net 2.0. I am looking for a smart quick way to combine two hash tables. At the moment I'm doing it like

foreach (string id in _unValidatedMachine) { _Machine.Add(id, _unValidatedMachine[id]); } _unValidatedMachine.Clear(); 

I don’t even check the inserted hash for an existing key here, maybe I should do this.

Any ideas how to make a merge?

+4
source share
1 answer

There is no standard way to combine two hashtables.

Yes, you have to check if the key is added, otherwise you can get an exception.

Also you can use:

 _Machine[id] = _unValidatedMachine[id]; 

In this case, if the key exists, you only overwrite its value.

+3
source

Source: https://habr.com/ru/post/1335958/


All Articles