Advertisement
Guest User

Untitled

a guest
Feb 26th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. Dictionary<int,string> DictA=new Dictionary<int,string>();
  2. DictA.Add(1,"A");
  3. DictA.Add(2,"B");
  4. DictA.Add(3,"C");
  5. DictA.Add(4,"D");
  6. Dictionary<string,string> DictB=new Dictionary<string,string>();
  7. DictB.Add("A","A1");
  8. DictB.Add("C","C1");
  9. DictB.Add("D","D1");
  10.  
  11. DictA
  12. .Select(x => new KeyValuePair<int,string>(x.Key,
  13. DictB.ContainsKey(x.Value)
  14. ? DictB[x.Value]
  15. : x.Value)
  16. .ToDictionary(x => x.Key, x => x.Value);
  17.  
  18. var result = DictA.ToDictionary(a => a.Key, a => DictB.ContainsKey(a.Value) ? DictB[a.Value] : a.Value);
  19.  
  20. foreach (var item in result)
  21. {
  22. Console.WriteLine(item.Key + ", " + item.Value);
  23. }
  24.  
  25. var result =
  26. DictA
  27. .ToDictionary(
  28. a => a.Key,
  29. a => DictB.ContainsKey(a.Value)
  30. ? DictB[a.Value]
  31. : a.Value);
  32.  
  33. DictA.ToList().ForEach(kv =>
  34. {
  35. if (DictB.ContainsKey(kv.Value))
  36. DictA[kv.Key] = DictB[kv.Value];
  37. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement