我在windows上以视觉方式编写了这段代码:
public static double timeTest(Func<List<int>, List<int>> method, int len)
{
System.Console.Write(String.Format("Testing {0} for {1} elements...\n", method.Method.Name, len));
/*snipped*/
}
它工作正常,产生的输出如下:
Testing foo for 500 elements...
但是后来我尝试用dotnet-cli
在linux上构建这个代码,它编译失败时遇到了这个错误:
/home/puck/lab6/Program.cs(22,92): error CS1061: 'Func<List<int>, List<int>>'
does not contain a definition for 'Method' and no extension method 'Method'
accepting a first argument of type 'Func<List<int>, List<int>>'
could be found (are you missing a using directive or an assembly reference?)
那么,问题是什么?
P.S:用method.Method.Name
System.Reflection.RuntimeReflectionExtensions.GetMethodInfo(method).Name
来解决我的问题