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

namespace ConsoleTest
{
public delegate void DelgCalc(int iWidth, int iHeight);

class delegateClass1
{
static void Main()
{
DelgCalc handler = new DelgCalc(delegateTest.CalcArea);
handler(6, 4);//计算面积

handler = new DelgCalc(delegateTest.CalcCircle);
handler(5, 4);//计算周长

Console.ReadLine();
}
}

public class delegateTest
{
public static void CalcArea(int iWidth, int iHeight)
{
Console.WriteLine("宽度:{0},高度:{1},面积:{2}", iWidth, iHeight, iWidth * iHeight);
}

public static void CalcCircle(int iWidth, int iHeight)
{
Console.WriteLine("宽度:{0},高度:{1},周长:{2}", iWidth, iHeight, (iWidth+ iHeight)*2);
}

}
}

运行效果:

delegate 委托一例(2)_class