Using LINQ:
double average = someDoubles.Average();
double sumOfSquaresOfDifferences = someDoubles.Select(val => (val - average) * (val - average)).Sum();
double sd = Math.Sqrt(sumOfSquaresOfDifferences / someDoubles.Length);
The sd
variable will have the standard deviation.
If you have a List
, then use someDoubles.Count
in the last line for code instead of someDoubles.Length
.