【问题标题】:Exit original function from another procedure从另一个过程中退出原始函数
【发布时间】:2015-07-03 00:26:44
【问题描述】:

在 C# 中有什么方法可以从另一个过程中退出函数吗?

例子:

void myFunction()
{
    checkLogin();    //make sure a user is logged in
    doOtherStuff();  //continue with other stuff
}
void checkLogin()
{
    if(loggedIn==false)
    {
        exitOriginalFunction(); // exit myFunction
    }
}

【问题讨论】:

  • 返回一个指示是否继续的值。或重构,这样就不需要这样的事情了

标签: c# function procedure


【解决方案1】:
void myFunction()
{
    if(!checkLogin())
       return;    //make sure a user is logged in
    doOtherStuff();  //continue with other stuff
}
void checkLogin()
{
    if(loggedIn==false)
    {
        return false; // exit myFunction
    }
    return true;
}

【讨论】:

    猜你喜欢
    • 2019-03-24
    • 2018-12-19
    • 2022-01-26
    • 2012-07-15
    • 2010-12-19
    • 1970-01-01
    • 2017-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多