在二维锯齿状数组中查找元素计数的标准方法是什么?

What is the standard way to find the elements count in a 2D jagged array?

    public static double PrazenWindowDensity(double [][] Xn, double x, double sigma2)
    {
        double gauss = 0;

        foreach(double [] arr in Xn)
        {
            foreach (double item in arr)
            {
                double xx = GausianFunction(item, x, sigma2);
                gauss += xx;
            }
        }

        return gauss / Xn.Length; //this is surely incorrect. Isn't it?
    }

我可以在这里写什么?

return gauss / Xn.Length;

这似乎是一个令人满意的答案,所以我会继续post它作为一个。

return gauss / Xn.Sum(x => x.Length);

我认为最快、最简单的方法是

public static double PrazenWindowDensity(double[][] Xn, double x, double sigma2)
{
    double gauss=0;
    int count=0;
    for (int i=0; i<Xn.Length; i++)
    {
        gauss+=Xn[i].Sum((item) => GausianFunction(item, x, sigma2));
        count+=Xn[i].Length;
    }
    return gauss/count;
}