using System; using System.Collections.Generic; public static class LinqQueryOperations{ public static IEnumerable MySelect (this IEnumerable source, Func selector){ foreach(TSource el in source) yield return selector(el); } public static IEnumerable MyWhere (this IEnumerable source, Func predicate){ foreach(TSource el in source) if (predicate (el)) yield return el; } public static TSource MyAggregate (this IEnumerable source, Func reducer){ IEnumerator e = source.GetEnumerator(); bool sourceNotEmpty = e.MoveNext(); if (sourceNotEmpty){ TSource result = e.Current; while(e.MoveNext()) result = reducer(result, e.Current); return result; } else throw new InvalidOperationException("Source must be non-empty"); } public static int MyCount (this IEnumerable source){ return source .MySelect(p => 1) .MyAggregate((r,i) => r + i); } }