Below is function to calculate mean from an array using c#. This is static function so you can make use of this to get Average of an array.

Below function will accept Array of double and you the mean or averageĀ of that array

public static double GetMean(double[] Values)

{

double mean = 0;

foreach (double average in Values)

{

mean += average;

}

mean /= Values.Length;

return mean;

}

Vb.NET code sample

Public Shared Function GetMean(ByVal Values As Double()) As Double

Dim mean As Double = 0

For Each average As Double In Values

mean += average

Next

mean /= Values.Length

Return mean

End Function

Hope this will help all who want to calculate mean or average from an array.