/****************************************/
/*★ Delegate を引数で渡す 前田 稔 ★*/
/****************************************/
using System;
namespace ConsoleApp
{
delegate int TestDelegate( int x, int y );
class Class2
{
public int methodMult( int x, int y )
{
return x*y;
}
public int methodPlus( int x, int y )
{
return x+y;
}
}
class Class1
{
public static void callm( int x, int y, TestDelegate callMethod )
{
int result = callMethod( x, y );
Console.WriteLine( result );
}
static void Main(string[] args)
{
Class2 class2 = new Class2();
callm( 3, 4, new TestDelegate( class2.methodMult ) );
callm( 3, 4, new TestDelegate( class2.methodPlus ) );
Console.ReadLine();
}
}
}
|