Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'          linq/ex2.cs - The average age of all females - basic version.Lecture 16 - slide 4 : 11
Program 3

using System;
using System.Collections.Generic;
using System.Linq;

public class Example1{
  
  public static void Main(){

    // The average age of all females - basic version.
    // Uses only Select, Where and Aggregate.

    IEnumerable<int> ages = Person.SomePersons
       .Where(p => p.Sex == Sex.Female)
       .Select(p => p.Age);

    double result =
       ages.Aggregate(0.0, (sum,i) => sum + i) / ages.Count();

   Console.WriteLine("Result = {0}", result);  // Result = 37,3333333333333
  }
}