小编SRI*_*NTH的帖子

目标参数计数异常:C#

尝试通过字符串调用函数

{
    object[] Parms = new object[] { "oiad", "abdj", "i" };
    Type thisType = GetType();
    MethodInfo theMethod = thisType.GetMethod("invo");
    ParameterInfo[] parameters = theMethod.GetParameters();

    if (parameters.Length != 0)
    {
      theMethod.Invoke(_instance, Parms);
    }
}

public void invo(object[] per)
{
    //
}
Run Code Online (Sandbox Code Playgroud)

例外:

TargetParameterCountException: Number of parameters specified does not match the expected number.
System.Reflection.MonoMethod.ConvertValues (System.Reflection.Binder binder, System.Object[] args, System.Reflection.ParameterInfo[] pinfo, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) (at <7d97106330684add86d080ecf65bfe69>:0)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <7d97106330684add86d080ecf65bfe69>:0)
System.Reflection.MethodBase.Invoke (System.Object …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

2
推荐指数
1
解决办法
3102
查看次数

标签 统计

c# ×1

unity-game-engine ×1