如何计算C#中的excel百分位数? [英] How to calculate excel percentile in C#?

查看:326
本文介绍了如何计算C#中的excel百分位数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,我在C#中,从列值列表中获取百分位数。请检查下面的代码,让我知道如何将参数传递给方法。



隐藏复制代码

  public   double 百分位数( double  []序列, double  excelPercentile)
{
Array.Sort(sequence);
int N = sequence.Length;
double n =(N - 1 )* excelPercentile + 1 ;
// 另一种方法:double n =(N + 1)* excelPercentile;
if (n == 1d) return sequence [ 0 ];
else if (n == N) return sequence [N - 1 ];
else
{
int k =( INT )n表示
double d = n - k;
return sequence [k - 1 ] + d *(sequence [k] - sequence [ k - 1 ]);
}
}



我有数据数组 - 而且k值为0.95。

百分位数(myarray,K);

以上方法向我发送错误。请告诉我,我的错误是什么。



我尝试了什么:



当我打电话给方法时



百分位数(myarray,K);

i在调用方法时有疑问



错误:

非静态字段方法需要对象引用。

解决方案

< blockquote>错误非静态字段,方法或属性需要对象引用已有详细记录。请检查:编译器错误CS0120 [ ^ ]


Hello All , i'm stucked in C# , to get the percentile from array of column values .please check the below code and let me know how can i pass the arguments to the method .

Hide Copy Code

public double Percentile(double[] sequence, double excelPercentile)
        {
            Array.Sort(sequence);
            int N = sequence.Length;
            double n = (N - 1) * excelPercentile + 1;
            // Another method: double n = (N + 1) * excelPercentile;
            if (n == 1d) return sequence[0];
            else if (n == N) return sequence[N - 1];
            else
            {
                int k = (int)n;
                double d = n - k;
                return sequence[k - 1] + d * (sequence[k] - sequence[k - 1]);
            }
        }


and i have the array of data - and also k value as 0.95.
percentile(myarray , K);
the above method sending me error . please let me know , what is my mistake.

What I have tried:

When i call the method

percentile(myarray , K);
i have doubt here at calling the method

Error :
Object reference is required for non-static field, method .

解决方案

The error "An object reference is required for the non-static field, method, or property" is well documented. Check this: Compiler Error CS0120[^]


这篇关于如何计算C#中的excel百分位数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆