0

我有以下列表:

var list1 = new List<string> {"m1", "m2", "m3"};
var list2 = new List<List<string>> 
    {
        new List<string>{"m1", "m2", "m3"},//1
        new List<string>{"m1", "m2", "m3", "m4", "m5"},//2
        new List<string>{"m4", "m5", "m3", "m45", "m35"},//3
        new List<string>{"m1", "m36", "m43", "m54", "m54"},//4
        new List<string>{"m2", "m4", "m3", "m44", "m55"}//5
    };

list2我想选择包含list1所有元素的每个列表。
我们应该如何以优化的方式来做

4

2 回答 2

2

您可以使用ExceptandAny方法:

var results = list2.Where(x => !list1.Except(x).Any())
于 2013-05-04T00:56:15.417 回答
2
list2.Where(l2 => list1.Intersect(l2).Count()==list1.Count)
于 2013-05-04T00:49:21.967 回答