委托定义
using System; namespace C重载 {//定义一个委托跟函数差不多,区别在于定义委托需要加上delegate关键字委托定义不需要函数体 delegate double MyDelegate( double par1,double par2); class Program { static double MUL( double par1,double par2){ return par1*par2; } static double Divide( double par1,double par2){ return par1/par2; } public static void Main(string[] args) { MyDelegate de;//利用委托我们定义的委托类型声明变量 de=MUL;//当我们给一个委托的变量赋值的时候,返回值跟参数列表必须一样,否则无法赋值 de(2.0,34.1); Console.WriteLine(de(2.0,34.1)); de =Divide; de(2.0,34.1); Console.WriteLine(de(2.0,34.1)); // TODO: Implement Functionality Here Console.Write("Press any key to continue . . . "); Console.ReadKey(true); } } }