1.把方法當作參數傳到另一個方法裡面使用
好處:可以快速切換多個方法,不用改名字
protected void Button1_Click(object sender, EventArgs e)
{
customAction = Test1;
Label1.Text=Test2(11, customAction).ToString();
}
public delegate double Predicate(double s);
Predicate customAction;
public double Test2(double number,Predicate c)
{
number=c(number);
return number;
}
private double Test1(double amount) {
amount++;
return amount;
}
參考:
https://eric0806.blogspot.tw/2015/01/dotnet-delegate-usage.html
沒有留言:
張貼留言