How to merge two didctionaries in C# with duplicates
Posted
by user320587
on Stack Overflow
See other posts from Stack Overflow
or by user320587
Published on 2010-04-19T17:46:10Z
Indexed on
2010/04/19
18:03 UTC
Read the original article
Hit count: 820
Hi, Is there a way in C# to merge two dictionaries? I have two dictionaries that may has the same keys, but I am looking for a way to merge them so, in the end there is a dictionary with one key and the values from both the dictionaries merged. I found the following code but it does not handle duplicates.
Dictionary Mydictionary<string, string[]> = new Dictionary<string, string[]>();
Mydictonary.Union(secondDictionary).ToDictionary( pair => pair.Key, pair => pair.Value);
© Stack Overflow or respective owner