fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Test
  6. {
  7. private static void Main()
  8. {
  9. List<List<FilteredVM>> groupedExpressionResults = GetDataSample();
  10.  
  11. IEnumerable<int> ids = groupedExpressionResults.Aggregate((x, y) => x.Where(xi => y.Select(yi => yi.ID).Contains(xi.ID)).ToList()).Select(x => x.ID);
  12.  
  13. // ids : { 3, 7 };
  14. foreach (var i in ids)
  15. {
  16. Console.WriteLine(i);
  17. }
  18. }
  19.  
  20. private static List<List<FilteredVM>> GetDataSample()
  21. {
  22. var lst1 = new List<FilteredVM>
  23. {
  24. new FilteredVM {ID = 2},
  25. new FilteredVM {ID = 3},
  26. new FilteredVM {ID = 7},
  27. new FilteredVM {ID = 9},
  28. };
  29. var lst2 = new List<FilteredVM>
  30. {
  31. new FilteredVM {ID = 3},
  32. new FilteredVM {ID = 6},
  33. new FilteredVM {ID = 7},
  34. };
  35. var lst3 = new List<FilteredVM>
  36. {
  37. new FilteredVM {ID = 3},
  38. new FilteredVM {ID = 5},
  39. new FilteredVM {ID = 7},
  40. new FilteredVM {ID = 8},
  41. };
  42.  
  43. return new List<List<FilteredVM>> { lst1, lst2, lst3 };
  44. }
  45. }
  46.  
  47. public class FilteredVM
  48. {
  49. public int ID { get; set; }
  50. public string Name { get; set; }
  51. public string Number { get; set; }
  52. }
  53.  
Success #stdin #stdout 0.05s 24424KB
stdin
Standard input is empty
stdout
3
7