Skip to content

Instantly share code, notes, and snippets.

@hidsh
Created October 4, 2011 08:25
Show Gist options
  • Save hidsh/1261147 to your computer and use it in GitHub Desktop.
Save hidsh/1261147 to your computer and use it in GitHub Desktop.
C# で汎関数 thanks to http://d.hatena.ne.jp/p-nix/20090226/p1
//
// 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