0
var lists = new List<List<string>>();
var a = new List<string> {"A", "B", "C", "D"};
var b = new List<string> {"A", "B", "C", "D" };
var c = new List<string> {"A", "Y", "C", "D" };
var d = new List<string> {"A", "B", "Z", "D" };
lists.Add(a);
lists.Add(b);
lists.Add(c);
lists.Add(d);

I need to get a list of value that is true for all lists (in this case it would be return {"A","D"})

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
ML13
  • 895
  • 8
  • 15
  • Can't anderstand what do you realy want, what filter? What condtition should be true? – Potato Nov 19 '19 at 04:31
  • Sounds like you want "all items that are present in all lists" which is "intersect multiple lists" (duplicate). Please [edit] the question if you are looking for something else with clear explanation and more than one example (i.e. what should happen for {"A","B"}, {"B","A"} ) – Alexei Levenkov Nov 19 '19 at 04:34
  • 1
    It can be done by `Linq` using code as `var result = lists.OrderBy(o => o.Count()).First().Where(s => lists.All(l => l.Contains(s)));` Here order by is used to select the lowest length list and checks its item in the list of list string. – user1672994 Nov 19 '19 at 04:39

0 Answers0