.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Code Snippets >> Collections >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Calculate mean from array in c#

Posted By:Amit Mehra       Posted Date: February 09, 2009    Points: 10    Category: Collections    URL: http://www.dotnetspark.com  

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


mean /= Values.Length

Return mean

End Function

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


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend