Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dictionary<int,string> DictA=new Dictionary<int,string>();
- DictA.Add(1,"A");
- DictA.Add(2,"B");
- DictA.Add(3,"C");
- DictA.Add(4,"D");
- Dictionary<string,string> DictB=new Dictionary<string,string>();
- DictB.Add("A","A1");
- DictB.Add("C","C1");
- DictB.Add("D","D1");
- DictA
- .Select(x => new KeyValuePair<int,string>(x.Key,
- DictB.ContainsKey(x.Value)
- ? DictB[x.Value]
- : x.Value)
- .ToDictionary(x => x.Key, x => x.Value);
- var result = DictA.ToDictionary(a => a.Key, a => DictB.ContainsKey(a.Value) ? DictB[a.Value] : a.Value);
- foreach (var item in result)
- {
- Console.WriteLine(item.Key + ", " + item.Value);
- }
- var result =
- DictA
- .ToDictionary(
- a => a.Key,
- a => DictB.ContainsKey(a.Value)
- ? DictB[a.Value]
- : a.Value);
- DictA.ToList().ForEach(kv =>
- {
- if (DictB.ContainsKey(kv.Value))
- DictA[kv.Key] = DictB[kv.Value];
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement