检查两个列表有碰撞的元素?元素、两个、列表

2023-09-04 07:48:45 作者:孟婆卖萌不卖汤

有没有一种方法来检查,如果一个列表与另一个发生碰撞?例如:

  BOOL命中= FALSE;
    的foreach(VAR S在list2中)
    {
        如果(list1.Contains(多个))
        {
            打= TRUE;
            打破;
        }
    }
    如果(!命中)
    {
 

解决方案

.NET有许多组操作上可枚举的工作,所以你可能需要的交集找到两个列表中的成员。使用任何()来看看生成的序列有任何条目。

例如。

 如果(list1.Intersect(list2中)。任何())
 

Cl元素在元素周期表中的位置是 检验是否含有铝的化学试剂是 净化汽车尾气中使NO,CO转化为无害气体的化学方程式为

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())