namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
var myDele = new TestDelegate();
myDele.Execute();
Console.ReadLine();
}
}
delegate int myDelegate(int x, int y);
class TestDelegate
{
public void Execute()
{
MessageShow(2, 2, Add);
MessageShow(2, 2, Sub);
}
public void MessageShow(int x,int y,Func<int,int,int> myDeli)
{
Console.WriteLine(myDeli(x, y));
}
public int Add(int x,int y)
{
return x + y;
}
public int Sub(int x, int y)
{
return x - y;
}
}
}
▸ 実行ボタンで結果を表示
Source収録記事
この snippet は記事の「Func<>で同じことをやってみる。」セクションに登場する。コードの前後の文脈・ハマりどころの解説は記事本文で。
