📌  相关文章
📜  检查列表是否存在于列表 c# 中是否匹配 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:00.934000             🧑  作者: Mango

代码示例4
You could use a nested Any() for this check which is available on any Enumerable:

bool hasMatch = myStrings.Any(x => parameters.Any(y => y.source == x));
Faster performing on larger collections would be to project parameters to source and then use Intersect which internally uses a HashSet so instead of O(n^2) for the first approach (the equivalent of two nested loops) you can do the check in O(n) :

bool hasMatch = parameters.Select(x => x.source)
                          .Intersect(myStrings)
                          .Any();