Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
C#
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 .
Posted
Updated 8-Aug-16 1:59am
v4
Comments
Patrice T 8-Aug-16 6:50am    
And you plan to tell us which error message and where ?
Mallesh Shantagiri 8-Aug-16 6:57am    
Hi , When i call the method as below
percentile(myarray , K); ,

Error : An object reference required for non -static field ,method,property.
Patrice T 8-Aug-16 7:00am    
Use Improve question to update your question.
Mallesh Shantagiri 8-Aug-16 7:04am    
Hi, I have updated the question , Please let me know how can i solve it.

1 solution

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900