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)
{
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())
If you're able to use Linq then if(list1.Intersect(list2).Count > 0) {...collision...}
.