i’ve three Dictonaries like
Dictionary<int,List<string>> D1 = new Dictionary<int,List<string>>();
Dictionary<int,List<string>> D2= new Dictionary<int,List<string>>();
Dictionary<int,List<string>> D3 new Dictionary<int,List<string>>();
D1[1] = new List<string>{"a","b"};
D1[2] = new List<string>{"c","d"};
D1[3] = new List<string>{"e","f"};
D1[4] = new List<string>{"h"};
D2[1] = new List<string>{"a","b"};
D2[2] = new List<string>{"c","d"};
D2[3] = new List<string>{"e","f"};
D2[4] = new List<string>{"g"};
D2[5] = new List<string>{"b","h"};
D2[6] = new List<string>{"f","l"};
D2[7] = new List<string>{"z"};
i need to merge the two dictonary into a single dictonary
like
D3[1] = {"a","b","h"}
D3[2] = {"c","d"}
D3[3] = {"e","f","l"}
Merging Rule:
D1[1]={“a”,”b”} this list will be compared with the values in the D2
D2[1]={“a”,”b”}
D2[5]={“b”,”h”}
so the above three will be merged into
D3[1]={“a”,”b”,”h”}
is there any idea to do this using LINQ
However are you trying to merge the values, you will probably want to use one of these options:
or
Edit – an ugly-looking method for joined merges Linq-style:
The code keeps the lists in D2, it would be pretty easy to modify the code to remove the matched lists from D2.