【问题标题】:CS0305, Invalid number of arguments when using System.Func delegateCS0305,使用 System.Func 委托时的参数数量无效
【发布时间】:2011-04-15 09:14:42
【问题描述】:

我收到以下错误:

error CS0305: Using the generic type 
'System.Func<T1,T2,T3,T4,T5,T6,T7,T8,T9,TResult>' 
requires '10' type arguments

在这一行:

public static IDoubleArray ApplyFunc(IDoubleArray inputArray1, 
                          IDoubleArray inputArray2, 
                           Func<double, double, double> f) {

System 命名空间中的 Func 定义如下所示:

[TypeForwardedFrom("System.Core, Version=3.5.0.0, 
                    Culture=Neutral,      
                    PublicKeyToken=b77a5c561934e089")]
public delegate TResult 
       Func<in T1, in T2, out TResult>(T1 arg1, T2 arg2);

一切看起来都很好,但编译器不这么认为。

有什么办法解决这个问题吗?

谢谢。

编辑:

调用如下所示:

/// <summary>Inverse cumulative distribution function</summary> 
        /// <param name="p">Probabilities at which to compute the inverse cdf</param>
        /// <param name="mu">Scale parameters</param>
        public static IDoubleArray Inv(IDoubleArray p, IDoubleArray mu)
        {
            return ArrayMath.ApplyFunc(Matrix.ConvertToMatrix(p), Matrix.ConvertToMatrix(mu), Inv);
        }

【问题讨论】:

  • ApplyFunc 的调用是什么样子的
  • 你确定错误信息不是The best overloaded method match for '...ApplyFunc(IDoubleArray, IDoubleArray, System.Func&lt;double,double,double&gt;)' has some invalid arguments...
  • 因为您传递给ApplyFuncInv 函数有一个签名= (IDoubleArray, IDoubleArray, IDoubleArray)ApplyFunc 需要(double, double, double) 还是我偏离了轨道?
  • ApplyFunc 有签名 (IDoubleArray, IDoubleArray, Func)。还有另一个带有签名的 Inv 函数(双精度、双精度)。但这不是问题。该错误是在 ApplyFunction 定义中生成的,因此调用无关紧要。感谢您的评论。

标签: c# delegates


【解决方案1】:

解决了。问题是目标不是 .NET 4.0。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-22
    • 1970-01-01
    • 1970-01-01
    • 2021-09-24
    • 1970-01-01
    • 1970-01-01
    • 2018-10-03
    相关资源
    最近更新 更多