【问题标题】:Strange C# compiler error奇怪的 C# 编译器错误
【发布时间】:2009-11-14 14:34:43
【问题描述】:

谁能帮我解决这个编译器错误?

我有这样的课

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' does not take '1' arguments。”

【问题讨论】:

    标签: c# compiler-errors


    【解决方案1】:

    我相信编译器无法推断参数,您需要明确指定它们的类型:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-23
      • 2011-03-22
      • 1970-01-01
      • 2019-12-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多