Advertisement
Fhernd

FunctionalMethods.cs

Feb 25th, 2016
5,835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement