LINQ: List Contains List

检查list包含list的情况
LINQ: List Contains 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.

参考:https://*.com/questions/13715529/check-whether-a-liststring-contains-an-element-in-another-liststring-using-l

上一篇:flutter应用开发中文本样式 TextStyle 篇


下一篇:标准的SQL语句类型