delegate 委托一例(2)

来源:互联网 发布:淘宝售后客服管理制度 编辑:程序博客网 时间:2024/05/06 05:57
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);        }    }}


运行效果: