Averages/Arithmetic mean: Difference between revisions

(→‎{{header|Python}}: Works with 3.0)
Line 152:
 
=={{header|C sharp|C#}}==
<lang csharp>static floatdouble avgAverage(ICollection<int>[] inumbers)
{
if (numbers == null || numbers.Length == 0)
return i.Sum() / (float)i.Count;
return 0;
 
double sum = 0;
for (int i = 0; i < numbers.Length; i++)
sum += numbers[i];
return sum/numbers.Length;
}
 
static void Main(string[] args)
{
int[] numbers = new int[] {1, 2, 3, 4, 5, 6, 7, 8};
Console.WriteLine(avg(numbers));
}</lang>
 
C# already has a builtin Avarage function.
 
<lang csharp>static void Main(string[] args)
{
int[] numbers = new{ int[] {1, 2, 3, 4, 5, 6, 7, 8 };
Console.WriteLine(numbers.Average(numbers));
}</lang>
 
Anonymous user