标签:
class FangFa { /// <summary> /// 加法运算 /// </summary> /// <param name="a">第一个数</param> /// <param name="b">第二个数</param> /// <returns></returns> public int JiaFa(int a, int b) { return a + b; } /// <summary> /// 减法运算 /// </summary> /// <param name="a">第一个数</param> /// <param name="b">第二个数</param> /// <returns></returns> public int JianFa(int a, int b) { return a - b; } }
//声明委托类型 public delegate int FirstDelegate(int a, int b); class Program { static void Main(string[] args) { //委托变量的定义及赋值 FirstDelegate f1 = new FangFa().JiaFa; //使用委托 int c1 = f1(5,4); Console.WriteLine("5+4="+c1); FirstDelegate f2 = new FangFa().JianFa; int c2 = f2(5, 4); Console.WriteLine("5-4="+c2); Console.ReadKey(); } }
标签:
原文地址:http://www.cnblogs.com/xiao55/p/5600415.html