有没有办法检查一个列表是否与另一个列表冲突?例如:
bool hit=false;
foreach(var s in list2)
{
if (list1.Contains(s))
{
hit = true;
break;
}
}
if (!hit)
{
最佳答案
.NET 有许多可枚举的集合操作,因此您可以采用 the set intersection在两个列表中查找成员。使用 Any()
查明生成的序列是否有任何条目。
例如
if(list1.Intersect(list2).Any())
关于c# - 检查两个列表是否有冲突元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3682729/