Posted on 2007-11-22 18:00
Java蜘蛛人 --郑成桥 阅读(220)
评论(0) 编辑 收藏
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication8


{
class Test

{
public void show(int num1, int num2)

{
int d = num1 * num2;
Console.WriteLine("相乘的结果{0}", d);
}
public void show1(int num1, int num2)

{
int h= num1 / num2;
Console.WriteLine("相除的结果{0}",h);
}
public void show2(int num1, int num2)

{

int c = num1 * num2*10;
Console.WriteLine("相乘乘以10的结果{0}", c);
}
}
}

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication8


{
public delegate void Mydelegate(int num1,int num2);
class Program

{
static void Main(string[] args)

{
Test aa = new Test();
//定义委托的好处就是这里 aa.show 如果该一下 改成aa.show1 这样 代码不用修改很多 达到的效果也是一样的

Mydelegate [] dd =
{new Mydelegate(aa.show),new Mydelegate(aa.show1),new Mydelegate(aa.show2)};
//dd[0](5,4);
haha(dd, 5, 4);
}
public static void haha(Mydelegate[] asd, int x, int y)

{
for (int i = 0; i <= 2; i++)
asd[i](x, y);
}
}
}
