简单方法调用:无法从用法推断出类型参数

fss*_*fss 5 c# compiler-errors

我偶然发现了一个我无法解释的错误.

以下代码导致Visual Studio 2015中的编译器错误:

class Program {
  private static void DoSomethingWithParameter(string s) { }

  private static void RegisterMethod<T>(Action<T> method) { }

  static void Main(string[] args) {
    RegisterMethod(DoSomethingWithParameter);
  }
}
Run Code Online (Sandbox Code Playgroud)

错误:

错误CS0411无法从用法推断出方法'Program.RegisterMethod <T>(Action <T>)'的类型参数.尝试显式指定类型参数.

如果我将方法调用更改为

RegisterMethod<string>(DoSomethingWithParameter);
Run Code Online (Sandbox Code Playgroud)

有用.

我认为编译器应该能够从第一个方法调用中推断出正确的类型,但事实并非如此.有人可以向我解释一下吗?