fork(10) download
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. var list1 = new[] { new { ID = 1 }, new { ID = 2 }, new { ID = 3 } };
  9. var list2 = new[] {
  10. new {
  11. ID = 1,
  12. Name = "Jason"
  13. },
  14. new {
  15. ID = 1,
  16. Name = "Jim"
  17. },
  18. new {
  19. ID = 2,
  20. Name = "Mike"
  21. },
  22. new {
  23. ID = 3,
  24. Name = "Phil"
  25. }
  26. };
  27.  
  28. var lst = (
  29. from lst1 in list1
  30. join lst2 in list2 on lst1.ID equals lst2.ID into lstGroup
  31. select lstGroup.First()
  32. );
  33.  
  34. foreach(var item in lst)
  35. {
  36. Console.WriteLine("ID: {0}, Name: {1}", item.ID, item.Name);
  37. }
  38. }
  39. }
Success #stdin #stdout 0.04s 37272KB
stdin
Standard input is empty
stdout
ID: 1, Name: Jason
ID: 2, Name: Mike
ID: 3, Name: Phil