C# 查找二维列表的特定维度的长度

C# 查找二维列表的特定维度的长度,c#,list,multidimensional-array,count,2d,C#,List,Multidimensional Array,Count,2d,在执行以下循环之前,我需要检查二维整数列表“centreX1”的第一个维度的长度: for (x = 0; x < (int)centreX1[0].Count(); x++) { if (BinarySpotsInsideTolerance1[0][x] == 1) { AllspotsY.Add(centreY1[0][x]);

在执行以下循环之前,我需要检查二维整数列表“centreX1”的第一个维度的长度:

  for (x = 0; x < (int)centreX1[0].Count(); x++)
            {
                if (BinarySpotsInsideTolerance1[0][x] == 1)
                {
                    AllspotsY.Add(centreY1[0][x]);
                    AllspotsX.Add(centreX1[0][x]);
                    AllspotsRLU.Add(RLUSpotsthreshold1[0][x]);
                }
            }
(x=0;x<(int)centreX1[0].Count();x++)的

{
如果(二进制SPOTsinSideTolerance1[0][x]==1)
{
AllspotsY.Add(centreY1[0][x]);
AllspotsX.Add(centreX1[0][x]);
AllspotsRLU.Add(RLUSpotsthreshold1[0][x]);
}
}

在centreX1[0]处引发错误。如果centreX1没有成员,则Count()

如果
centreX1
没有元素,则无法计算
centreX1[0]
中的元素数

在尝试访问第一个元素之前,请确保
centreX1
中包含元素

if (centreX1.Any())  // or "if (centreX1.Count() > 0)"
{
    for (x = 0; x < (int)centreX1[0].Count(); x++)
    {
        if (BinarySpotsInsideTolerance1[0][x] == 1)
        {
            AllspotsY.Add(centreY1[0][x]);
            AllspotsX.Add(centreX1[0][x]);
            AllspotsRLU.Add(RLUSpotsthreshold1[0][x]);
        }
    }
}
if(centreX1.Any())//或“if(centreX1.Count()>0)”
{
对于(x=0;x<(int)centreX1[0]。计数();x++)
{
如果(二进制SPOTsinSideTolerance1[0][x]==1)
{
AllspotsY.Add(centreY1[0][x]);
AllspotsX.Add(centreX1[0][x]);
AllspotsRLU.Add(RLUSpotsthreshold1[0][x]);
}
}
}

在运行代码之前,请检查
centreX1.Count>0
。如果是数组,则答案在问题标题中。非数组-整数列表