C#中有没有办法从另一个程序中退出函数?
示例:
void myFunction()
{
checkLogin(); //make sure a user is logged in
doOtherStuff(); //continue with other stuff
}
void checkLogin()
{
if(loggedIn==false)
{
exitOriginalFunction(); // exit myFunction
}
}
答案 0 :(得分: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;
}