为什么我的 C# 脚本中会出现此错误?没有给出对应于所需形式参数的参数 'Type'

Why am I getting this error in my C# script? There is no argument given that corresponds to the required formal parameter 'Type'

这是我正在尝试做的,但不幸的是我收到了上述错误:

void Function1() { 
    if() { 
        Function2(); 
    } 

    else {…} 
    } 

public static void Function2 (Type type) {
…
}

您在 Function2 中遗漏了参数名称。

public static void Function2 (Type)

应该是:

public static void Function2 (Type type)

根据您的 Function1 实施,您没有将参数传递给 Function2。那将是另一个问题。

No overload for method 'Function2' takes 0 arguments

如果 Function2 可以不带参数接受,你可以用

  1. 方法重载(声明另一个没有参数的Function2)
public static void Function2 () { }
  1. 使用可选参数
  2. 更改电流Function2
public static void Function2 (Type type = null) { }

已更新:

由于 Post 所有者提到 Function2 需要 1 个参数,因此在您的 Function1() 中,您需要传递该值以调用 Function2.

void Function1() 
{ 
    if(/* when condition is true */)
    { 
        Function2(/* pass your value */); 
    } 
    else {…} 
}