Calculates the average - CSharp System

CSharp examples for System:Math Statistics

Description

Calculates the average

Demo Code

// Permission is hereby granted, free of charge, to any person obtaining a copy
using System.Linq;
using System.Collections.Generic;
using System;/*w  w  w .  java  2 s  . c  om*/

public class Main{
        /// <summary>
        /// Calculates the average
        /// </summary>
        /// <param name="numbers">Double-values</param>
        /// <returns>Average</returns>
        public static double Average(List<double> numbers)
        {
            if (numbers != null) return numbers.Sum()/numbers.Count();

            throw new ArgumentException("Numbers are null or 0", "numbers");

        }
}

Related Tutorials