Mean of IEnumerable<double> - CSharp System

CSharp examples for System:Math Statistics

Description

Mean of IEnumerable<double>

Demo Code

// This project is licensed under the BSD license.  See the License.txt file for more information.
using System.Globalization;
using System.Collections.Generic;
using System;//  w w  w  . ja  v a  2 s .c  o m

public class Main{
        public static double Mean(this IEnumerable<double> values)
        {
            double sum = 0;
            int count = 0;

            foreach(double d in values)
            {
                sum += d;
                count++;
            }

            return sum / count;
        }
}

Related Tutorials