从一些代码方法中,去学习C#委托
class Bc { public double Add(double number1, double number2) { return number1 + number2; } public double Multiply(double number1, double number2) { return number1 * number2; } public double Subtract(double number1, double number2) { return number1 - number2; } public double Division(double number1, double number2) { return number1 / number2; } }
class Bd { public delegate double CalcResult(double number1, double number2); public void TestDelegate() { Bc objBc = new Bc(); CalcResult obj = new CalcResult(objBc.Multiply); Console.WriteLine(obj(2, 5)); } }
在控制台运行: