LINQ: List Contains List
作者:互联网
检查list包含list的情况
List<string> a = ...
List<string> b = ...
var inComon = a.Intersect(b).Any();
Use Enumerable.Any Method:
List<string> l1 = new List<string> { "1", "2" };
List<string> l2 = new List<string> { "1", "3" };
var result = l2.Any(s => l1.Contains(s));
I'd say the Intersect method (see answer by dasblinkenlight) + Any must work better than Contains + Any. It is definetely better to use Any than Count.
标签:Contains,List,LINQ,better,Intersect,var,Any 来源: https://www.cnblogs.com/tangge/p/15440226.html