有没有一种方法来检查,如果一个列表与另一个发生碰撞?例如:
BOOL命中= FALSE;
的foreach(VAR S在list2中)
{
如果(list1.Contains(多个))
{
打= TRUE;
打破;
}
}
如果(!命中)
{
解决方案
.NET有许多组操作上可枚举的工作,所以你可能需要的交集找到两个列表中的成员。使用任何()
来看看生成的序列有任何条目。
例如。
如果(list1.Intersect(list2中)。任何())
Is there a way to check if one list collides with another? ex:
bool hit=false;
foreach(var s in list2)
{
if (list1.Contains(s))
{
hit = true;
break;
}
}
if (!hit)
{
解决方案
.NET has a number of set operations that work on enumerables, so you could take the set intersection to find members in both lists. Use Any()
to find out if the resulting sequence has any entries.
E.g.
if(list1.Intersect(list2).Any())