Created
October 4, 2011 08:25
-
-
Save hidsh/1261147 to your computer and use it in GitHub Desktop.
C# で汎関数 thanks to http://d.hatena.ne.jp/p-nix/20090226/p1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// C# で汎関数 | |
// http://d.hatena.ne.jp/p-nix/20090226/p1 | |
// | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
process(add); | |
process(mul); | |
while (Console.ReadKey().ToString() == "") ; | |
} | |
private static int add(int x, int y) | |
{ | |
return x + y; | |
} | |
private static int mul(int x, int y) | |
{ | |
return x * y; | |
} | |
private static void process(Func<int, int, int> calc) | |
{ | |
Console.WriteLine("前処理"); | |
Console.WriteLine(calc(2, 3)); | |
Console.WriteLine("後処理"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment