using System;
using System.Collections.Generic;
using System.Linq;
namespace NilPointer
{
class Program
{
static void Main(string[] args)
{
var numbers = new List<int> {
50, 2, -7, 11,-9, 26, 6, 42
};
var average1 = numbers.Average(number => number);
Console.WriteLine("Average 1: " + average1);
var average2 = numbers.Where(number => number > 0).Average(number => number);
Console.WriteLine("Average 2: " + average2);
Console.ReadLine();
}
}
}
Output
Average 1: 15.125
Average 2: 22.83