fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. class Device
  8. {
  9. public List<string> Interfaces { get; set; }
  10. }
  11.  
  12. static List<Device> allDevices = new List<Device>()
  13. {
  14. new Device{Interfaces=new List<string>{"1","2","3"}},new Device{Interfaces=new List<string>{"1","2","3"}},
  15. new Device{Interfaces=new List<string>{"1","NO!","3"}},new Device{Interfaces=new List<string>{"1","2","3"}},
  16. new Device{Interfaces=new List<string>{"1","2","3"}},new Device{Interfaces=new List<string>{"1","2","3"}},
  17. };
  18.  
  19. public static void Main()
  20. {
  21. IEnumerable<string> commonSubset = new List<string>(allDevices.First().Interfaces);
  22. foreach (List<string> interfaces in allDevices.Skip(1).Select(d => d.Interfaces))
  23. {
  24. commonSubset = commonSubset.Intersect(interfaces);
  25. if (!commonSubset.Any())
  26. break;
  27. }
  28.  
  29. Console.Write(String.Join(",", commonSubset.ToArray()));
  30. }
  31. }
Success #stdin #stdout 0.03s 33896KB
stdin
Standard input is empty
stdout
1,3