Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 搜索列表数组_C#_List - Fatal编程技术网

C# 搜索列表数组

C# 搜索列表数组,c#,list,C#,List,我有一个列表数组[k](多个列表) 我想搜索列表[k]中的变量PointF是否等于列表中的任何元素,变量PointF来自的列表除外 类似于在列表k+1,k+2,k+n和k-1,k-2,k-n上搜索,k除外 for (int k = 0; k < drone.Length; k++) { for (int i = 0; i <= 10; i++) { for (int j = 0; j <= 10; j++) {

我有一个列表数组[k](多个列表)

我想搜索列表[k]中的变量PointF是否等于列表中的任何元素,变量PointF来自的列表除外

类似于在列表k+1,k+2,k+n和k-1,k-2,k-n上搜索,k除外

for (int k = 0; k < drone.Length; k++) 
{
    for (int i = 0; i <= 10; i++) 
    {
        for (int j = 0; j <= 10; j++) 
        {
            list[k].Add(new PointF(i,j));
        }
    }

    // now I want to search if a variable PointF 
    // from a list[k] is equals to any of the elements 
    // of the lists except the list where that variable PointF comes from
}
for(int k=0;k对于(int i=0;i如果您知道
k
(您的点来自的列表的索引),您可以通过这个小小的linq实现来实现这一点:

private bool PointExistsInAnotherList(List<PointF>[] lists, int k, PointF p)
{
    return Enumerable.Range(0, lists.Length)
                     .Where(i => i != k)
                     .Any(i => lists[i].Any(point => point.Equals(p)));

}

这将返回索引(
i
)第一个列表中包含等于
p
,或
-1
的点(如果未找到匹配点)。

是否要搜索特定的给定点或确定任何列表中是否有任何点也存在于另一个列表中?我从列表中获取一个元素,并将该元素与所有元素进行比较在所有列表中,除了该元素来自的列表之外。好吧,那么你知道
k
?这是一个打字错误并且
drone
list
还是
drone
中有其他魔法?我猜
j是的。对不起,忘记删除了。你在吗?你知道如何代替返回bool。我想返回哪个k列表吗找到了吗?@TiagoSilva更新我的答案。我无法用我的代码使它工作。你能检查一下吗?
private int PointExistsInAnotherList(List<PointF>[] lists, int k, PointF p)
{
    for (int i=0; i<lists.Length; i++)
    {
        if (i == k) continue;
        if (lists[i].Any(point => point.Equals(p)) return i;                                  
    }

    return -1;
}