既然返回值参数和方法都相同,为什么要用委托
看下面的例子:
form1中:
public static double Low(double T)
{
return 0.02*T;
}
private void button1_Click(object sender, System.EventArgs e)
{
double result;
DelegateCompute dc;
dc= new DelegateCompute(Form1.Low);
result = MoneyCompute.Compute(1000.0,dc);
另一个文件中MoneyCompute类:
using System;
public delegate double DelegateCompute(double x);
namespace WindowsApplication3
{
/// <summary>
/// Summary description for MoneyCompute.
/// </summary>
public class MoneyCompute
{
public static double Compute(double t, DelegateCompute dc)
{
return dc(t);
}
public MoneyCompute()
{
//
// TODO: Add constructor logic here
//
}
}
}
感觉搞得复杂好难理解啊,绕啊绕