从调用方法返回

s-a*_*a-n 0 .net c#

我有方法

public void x()
{
    y();
    z();
}

public void y()
{
    if(some condition) return;
    some code...
}

public void z()
{
    somecode...
}
Run Code Online (Sandbox Code Playgroud)

我知道method y()如果满足somecondition条件,将返回return语句而不执行该方法中的任何其他操作,并将返回method x()并执行method z().但有没有办法从method x()没有执行返回method z()

我无法改变任何约束或编辑 method y

Joh*_*136 5

y()返回某种代码来让x()知道是否调用z()或没有.

public void x()
{
    if (y())
    {
        z();
    }
}

// Return true if processing should continue.
//
public bool y()
{
    if(some condition) return false;
    some code...
    return true;
}

public void z()
{
    somecode...
}
Run Code Online (Sandbox Code Playgroud)