// File: TestHof.cs // Author: David Bergman // // This file is testing a mini framework for higher-order functions // that I implemented during a seminar at Lab49 // using System; using System.Collections.Generic; public class Test { public static int Add(int m, int n) { return m+n; } public static void Main(string[] args) { // Transform strings to ints IList myInts = new List(); // We can provide raw method references, and // they will be automatically wrapped into a // proper delegate - our chosen functoid type // - thanks to a C# 2.0 extension Hof.Transform(args, myInts, Int32.Parse); // Calculate the sum int sum = Hof.Accumulate(myInts, 0, Add); // Pick max // We can create a functoid on-the-fly, with inline definition // thanks to a C# 2.0 extension int max = Hof.Accumulate(myInts, 0, delegate(int m, int n) { return Math.Max(m, n); }); Console.WriteLine("Sum is {0}", sum); Console.WriteLine("Max is {0}", max); } }