您的位置:首页 > 其它

使用Func<>和Action简化委托

2015-04-07 11:18 363 查看
/// <summary>
/// 入口
/// </summary>
public void Run()
{
TestDelegate t = test;
t("a",10);
Action<string, int> actiont = test;
actiont("a", 10);
//以上两种方法,完全相等,第二种更为简洁
Test2Delegate t2 = calc;
calc(1,3);
Func<int, int, int> funct2 = calc;
funct2(1, 3);
//以上两种方法,完全相等,第二种更为简洁
}

public static void test(string a, int b)
{
Console.WriteLine(a+b);
}
public static int calc(int a, int b)
{
return a + b;
}

public delegate void TestDelegate(string a,int b);
public delegate int Test2Delegate(int a, int b);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: