fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5.  
  6. namespace myQuestion
  7. {
  8. class Program
  9. {
  10. public class DuplicateData
  11. {
  12. public string address { get; set; }
  13. }
  14.  
  15. public class Com : IEqualityComparer<DuplicateData>
  16. {
  17. public bool Equals(DuplicateData x, DuplicateData y)
  18. {
  19. return x.address.Equals(y.address);
  20. }
  21.  
  22. public int GetHashCode(DuplicateData obj)
  23. {
  24. return obj.address.GetHashCode();
  25.  
  26. }
  27. }
  28.  
  29. static void Main()
  30. {
  31. List<string> lst = new List<string>();
  32. lst.Add("a");
  33. lst.Add("b");
  34. lst.Add("c");
  35. lst.Add("p");
  36.  
  37. List<DuplicateData> list = new List<DuplicateData>()
  38. {
  39. new DuplicateData{address="a"},
  40. new DuplicateData{address="a"},
  41. new DuplicateData{address="a"},
  42. new DuplicateData{address="b"},
  43. new DuplicateData{address="b"},
  44. new DuplicateData{address="c"},
  45. new DuplicateData{address="d"},
  46. new DuplicateData{address="e"},
  47. new DuplicateData{address="f"},
  48. };
  49.  
  50. var dup = list.Distinct(new Com());
  51. var RightJoin = from x in dup
  52. join y in lst
  53. on x.address equals y
  54. into right
  55. from z in right.DefaultIfEmpty(x.address)
  56. select new
  57. {
  58. UniqueAddress = z,
  59.  
  60. };
  61.  
  62. foreach (var ex in RightJoin)
  63. {
  64. System.Console.WriteLine(ex.UniqueAddress);
  65. }
  66. System.Console.ReadLine();
  67. }
  68. }
  69. }
Success #stdin #stdout 0.04s 34128KB
stdin
Standard input is empty
stdout
a
b
c
d
e
f