Using the reproduced query operations. | Lecture 16 - slide 7 : 11 Program 2 |
using System; using System.Collections.Generic; // NOT using System.Linq; public class Example1{ public static void Main(){ // The average age of all females - basic version IEnumerable<int> ageSum = Person.SomePersons .MyWhere(p => p.Sex == Sex.Female) .MySelect(p => p.Age); double result = (double)(ageSum.MyAggregate((sum,i) => sum + i)) / ageSum.MyCount(); Console.WriteLine("Result = {0}", result); // Result = 37,3333333333333 } } |