1
Answer

[Help] How to calculate Standard Deviation of the data in Gridview C#

Jun Harefa

Jun Harefa

13y
3.8k
1
I want to calculate the standard deviation value based on the data displayed in the Gridview. However I'm confused since the standard deviation function is not available in c#.
As seen in the picture below, if I press the "Process" button, it will display the standard deviation results of the data.



How do I write the code?

Thanks before.
Answers (1)
0
Narayan

Narayan

NA 724 36.3k 13y
Try to use this function
public double CalCulateStdDev(List<double> lst)
        {
            if (lst == null || lst.Count == 0)
                throw new ArgumentException("Collection does not have anything to calculate");
            double d = 0;
            double average = lst.Average();
            d = Math.Sqrt(lst.Select(a => Math.Pow(a - average, 2)).Sum() / lst.Count);
            return d;
        }
Accepted