C#4.0 新特性 - 泛型委托,Action,Func用法
//Action 无返回值 执行一个void方法
Action<string> myAction;
//Func 最后一个参数接受返回值
Func<string, string> myFunc;
Action<string> action = new Action<string>(delegate(string name)
{
MessageBox.Show("Hello" + name);
});
private void Button_Click_1(object sender, RoutedEventArgs e)
{
myAction = TestAction;
myAction("myAction");
myFunc = TestFunc;
var a = myFunc("myFunc");
MessageBox.Show(myFunc.ToString());
}
void TestAction(string a)
{
MessageBox.Show(a);
}
string TestFunc(string a)
{
return a;
}