是否可以忽略'出'参数?

3 c# methods out-parameters

我有这样的方法......

public List<String> TestMethod(Int32 parameter, out Boolean theOutParameter)
{
}
Run Code Online (Sandbox Code Playgroud)

当我调用该方法时,如果我theOutParameter对该方法的调用看起来不感兴趣?bool如果我对该值不感兴趣,那么实例化一个新的只是有点过分,以便处理方法的out参数.

Mar*_*ell 6

不,但你可以添加一个重载:

public List<string> TestMethod(int parameter)
{
    bool tmp;
    return TestMethod(parameter, out tmp);
}
Run Code Online (Sandbox Code Playgroud)