Finding the intersection of any number of lists
If you want to find the set of numbers that exist in all of the lists then Enumerable.Intersect
is a good way to do so. You don't even have to hardcode the collection of lists, it can be created at runtime:
var lists = new[] { list1, list2, ..., listN }; // dynamically specified
var common = lists.First().AsEnumerable();
foreach (var list in lists.Skip(1))
{
common = common.Intersect(list);
}
// and now common has the result, e.g.
var listOfCommonEntries = common.ToList();
Finding the union of intersections between master list and each other one
If you want to find the set which includes all common numbers between list 1 and list 2, union all common numbers between list 1 and list N, then it's somewhat different:
var common = Enumerable.Empty<int>();
foreach (var list in lists.Skip(1))
{
common = common.Union(lists.First().Intersect(list));
}