fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7.  
  8. class item {
  9. public string name {get;set;}
  10. public int identifier {get;set;}
  11. public item (int identifier, string name) {
  12. this.name = name;
  13. this.identifier = identifier;
  14. }
  15. public override string ToString () {
  16. return string.Format("{0} / {1}",this.identifier,this.name);
  17. }
  18. }
  19.  
  20. public static void Main() {
  21. List<item> List1 = new List<item>(new item[]{
  22. new item(1,"a"),
  23. new item(2,"abandon"),
  24. new item(3,"abandoned"),
  25. new item(4,"ability"),
  26. new item(5,"able"),
  27. new item(6,"about"),
  28. new item(7,"above"),
  29. new item(8,"abroad"),
  30. new item(9,"absence"),
  31. new item(10,"absent"),
  32. new item(11,"absolute"),
  33. new item(12,"absolutely"),
  34. new item(13,"absorb"),
  35. new item(14,"abuse"),
  36. new item(15,"abuse"),
  37. new item(16,"academic"),
  38. new item(17,"accent"),
  39. new item(18,"accept"),
  40. new item(19,"acceptable"),
  41. new item(20,"access"),
  42. new item(21,"accident"),
  43. new item(22,"accidental"),
  44. new item(23,"accidentally"),
  45. new item(24,"accommodation"),
  46. new item(25,"accompany"),
  47. new item(26,"according to"),
  48. new item(27,"account")
  49. });
  50.  
  51. List<item> List2 = new List<item>(new item[] {
  52. new item(5,"foo"),
  53. new item(9,"bar"),
  54. new item(14,"qux"),
  55. new item(25,"notinscope")
  56. });
  57.  
  58. Dictionary<int,item> l2dic = List2.ToDictionary(x => x.identifier);
  59. item itm;
  60. foreach(item x in List1) {
  61. if(l2dic.TryGetValue(x.identifier,out itm)) {
  62. x.name = itm.name;
  63. }
  64. }
  65.  
  66. //print entries
  67. foreach(item x in List1) {
  68. Console.WriteLine(x);
  69. }
  70. }
  71. }
Success #stdin #stdout 0.05s 24320KB
stdin
Standard input is empty
stdout
1 / a
2 / abandon
3 / abandoned
4 / ability
5 / foo
6 / about
7 / above
8 / abroad
9 / bar
10 / absent
11 / absolute
12 / absolutely
13 / absorb
14 / qux
15 / abuse
16 / academic
17 / accent
18 / accept
19 / acceptable
20 / access
21 / accident
22 / accidental
23 / accidentally
24 / accommodation
25 / notinscope
26 / according to
27 / account