join unknown number of lists in linq

前端 未结 3 1128
青春惊慌失措
青春惊慌失措 2021-01-20 02:27

I have a situation where I have generated a number of lists which contain integer values. However, the number of these lists is only known at runtime, and i

3条回答
  •  终归单人心
    2021-01-20 02:46

    // lists is a sequence of all lists from l1 to ln
    if (!lists.Any())
       return new List();
    
    IEnumerable r = lists.First();   
    
    foreach(List list in lists.Skip(1))    
       r = r.Intersect(list);
    
    return r.ToList();
    

提交回复
热议问题