没有给出"出局"的论点

3Pi*_*3Pi 3 c#

可以将默认值分配给函数的正常参数,例如

bool SomeFunction(int arg1 = 3, int arg2 = 4)
Run Code Online (Sandbox Code Playgroud)

可以通过以下任何一种方式调用.

bool val = SomeFunction();
bool val = SomeFunction(6);
bool val = SomeFunction(6,8);
Run Code Online (Sandbox Code Playgroud)

有没有办法做类似的事情(除了创建一个未使用的变量),这样做

bool SomeOtherFunction(int arg1, out int argOut)
Run Code Online (Sandbox Code Playgroud)

可以通过以下任一方式调用?

int outarg;
bool val = SomeOtherFunction(4,outarg);
bool val = SomeOtherFunction(4);
Run Code Online (Sandbox Code Playgroud)

这有可能,或者如果没有,有什么好的解决方法?谢谢.

K-b*_*llo 6

一个好的解决方法是:

bool SomeOtherFunction(int arg1, out int argOut){ ... }

bool SomeOtherFunction(int arg1)
{
    int dummyArgOut;
    return SomeOtherFunction(arg1, dummyArgOut);
}
Run Code Online (Sandbox Code Playgroud)

我甚至会说它是最好的解决方法.