I have two Dictionary.
Dictionary<string, string> testDict = new Dictionary<string, string>();
testDict.Add("Name", "John");
testDict.Add("City", "NY");
Dictionary<string, string> DictA = new Dictionary<string, string>();
DictA.Add("Name", "Sarah");
DictA.Add("State", "ON");
I wish to get a Dictionary such that the keys of testDict are present and the values of those keys present in DictA are present.
So the example merged dictionary should look as below:
Dictionary<string, string> DictMerged = new Dictionary<string, string>();
DictMerged.Add("Name", "Sarah");
DictMerged.Add("City", "NY");
I hope I have been able to explain my requirements..
I tried..
testDict.Concat(DictA)
.GroupBy(kvp => kvp.Key, kvp => kvp.Value)
.ToDictionary(g => g.Key, g => g.Last());
But this gave me DictA 'State' as well which I do not want..
Any help is sincerely appreciated
Thanks