退货声明,这到底是什么意思? [英] Return statement, what exactly does it mean?

查看:97
本文介绍了退货声明,这到底是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好...

在这种情况下,退货到底会做什么?

Hi there...

What exactly will the return do in this case...

private void Method1 ()
{
   //some code here
   Method2(var1,var2);
}

private void Method2 (string var1,string var2)
{
    counter ++;
    
    if(counter < 3)
    {
       if(condition1 == condition2)
       {
           counter = 0;
           Method3();
           return;
       }
       if(condition1 != condition2)
       {
           //go back to method1 and try again
           Method1();
       }
    }
}

推荐答案

从到目前为止所看到的答案中,您无法获得正确的回报观念.尝试阅读并理解以下内容:
http://en.wikipedia.org/wiki/Call_stack [
From the answers you''ve see so far, you could not get a right idea of return. Try to read and understand this:
http://en.wikipedia.org/wiki/Call_stack[^].

—SA


这里的return语句表示从Method2中退出
Hi, return statement here means go out from Method2


return语句表示放弃对当前正在执行到调用方法的代码,即退出您在此方法中正在执行的操作,并返回到谁在从谁进行调用的下一条语句.

在您的情况下,Method2中的return将返回到Method1,并且由于Method1中没有更多代码,因此Method1也将完成.
A return statement means relinquish control of the currently executing code to the calling method, i.e. exit what you are doing in this method and go back to the next statement in who ever was calling from.

In your case the return in Method2 will go back to Method1 and since there is no more code in Method1, Method1 will finish also.


这篇关于退货声明,这到底是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆