Dav*_*vid 18
听起来你想将a保存Func到一个变量供以后使用.看看这里的例子:
using System;
public class GenericFunc
{
public static void Main()
{
// Instantiate delegate to reference UppercaseString method
Func<string, string> convertMethod = UppercaseString;
string name = "Dakota";
// Use delegate instance to call UppercaseString method
Console.WriteLine(convertMethod(name));
}
private static string UppercaseString(string inputString)
{
return inputString.ToUpper();
}
}
Run Code Online (Sandbox Code Playgroud)
看看如何将方法UppercaseString保存到一个被调用的变量中convertMethod,然后可以调用该变量:convertMethod(name).