代码之家  ›  专栏  ›  技术社区  ›  adrianm

奇怪的C#编译器错误

  •  1
  • adrianm  · 技术社区  · 16 年前

    有人能帮我解决这个编译器错误吗?

    我有一节这样的课

    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移动到另一个程序集(与上面的代码完全相同),我会得到一个编译器错误“委托'TestAction'不接受'1'参数。”

    1 回复  |  直到 16 年前
        1
  •  2
  •   Darin Dimitrov    16 年前

    Test.Call((int arg, TestAction<int> action) => action(arg));