我在调用具有不同Action<T>变体的重载方法时遇到了一些意外的编译器行为.
假设我有这个类Test,我在CallTest构造函数中创建它的实例.
public class Test
{
public Test(Action<long> arg)
{
}
public Test(Action<decimal> arg)
{
}
}
public class CallTest
{
public CallTest()
{
Test t = new Test(TestDecimal);
}
public void TestDecimal(decimal arg)
{
}
public void TestLong(long arg)
{
}
}
Run Code Online (Sandbox Code Playgroud)
当Test使用TestDecimal或TestLong作为参数调用构造函数时,我收到以下错误:
以下方法或属性之间的调用不明确:'
Test(System.Action<long>)'和'Test(System.Action<decimal>)'
我的猜测是有一些隐式转换之间正在进行的long和decimal,但没有任何人有任何其他想法可能我做错?有没有解决方法?