内置的委托类型Func
static void Main(string[] args)
{
    Func<int, int, string> func = ReturnFunction;
    Console.WriteLine(func(1, 2));

    Console.ReadKey();
}

static string ReturnFunction(int a, int b) {
    return "a+b=" + (a + b);
}

Func通过指定泛型<T1,T2...Return>,前面指定参数的类型,最后一个指定返回的类型

Func对比Action就是它可以承载带返回的函数


首页 我的博客
粤ICP备17103704号