fork download
  1. using System;
  2.  
  3. namespace Recipes.LINQ.R0102
  4. {
  5. public class FunctionalMethods
  6. {
  7. public static void Main()
  8. {
  9. // Functional method f(x) and g(x):
  10. Func<int, int> f = x => x + 1;
  11. Func<int, int> g = x => x + 2;
  12.  
  13. // Compound functional method f(g(x)):
  14. Func<Func<int, int>, Func<int, int>, int, int> fog = (f1, g1, x) => f1.Invoke(g1.Invoke(x));
  15.  
  16. Console.WriteLine();
  17. // Computing f(x) with x = 2:
  18.  
  19. Console.WriteLine("f(2) = {0}", f(2));
  20. Console.WriteLine("g(3) = {0}", g(3));
  21. Console.WriteLine("f(g(5) = {0}", fog(f, g, 5));
  22.  
  23. Console.WriteLine();
  24. }
  25. }
  26. }
Success #stdin #stdout 0.04s 23928KB
stdin
Standard input is empty
stdout
f(2) = 3
g(3) = 5
f(g(5) = 8