奇怪的C#编译器错误

时间:2009-11-14 14:34:44

标签: c# compiler-errors

有人可以帮我解决这个编译错误吗?

我有一个这样的课程

public class Test {
    public delegate void TestAction<T>(T arg);
    public delegate void TestActionCaller<T1, T2>(T1 arg, TestAction<T2> action);

    public static void Call<T1,T2>(TestActionCaller<T1,T2> actioncaller) {
        actioncaller(default(T1), arg => { });
    }
}

然后我有以下代码

public class TestCaller {
    static TestCaller() {
        Test.Call<int, int>((arg,action)=>action(arg));
    }
}

这很好用。

但是如果我将TestCaller移动到另一个程序集(与上面完全相同的代码),我得到一个编译器错误“Delegate'TestAction'不接受'1'参数。”

1 个答案:

答案 0 :(得分:2)

我认为编译器无法推断参数,您需要明确指定其类型:

Test.Call((int arg, TestAction<int> action) => action(arg));
相关问题