C#错误CS1061。获取方法名称

时间:2016-11-22 22:29:53

标签: c# .net linux methods .net-core

我在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来解决我的问题

0 个答案:

没有答案