2014-02-16 37 views
-5

我有一个类这样的(这是一个例子),我需要来自世界各地返回全班我需要它C#如何破解公共无效

Line1 :Public void test(bool start) 
Line2 :{ 
Line3 : if (start) //do something; 
Line4 : else // i use else for update with help other code and... forget it 
Line5 : { 
Line6 : if (xxX) 
Line7 :  if (sadasdas) 
Line8 :   if(sdaeqwr324f) 
Line9 :    if (Asdasdsa) 
Line10:     for (int a=0;a<6;a++) 
Line11:     { 
Line12:      if (c[a]==1321334) 
Line13:      { 
Line14:      t=c[1]; 
Line15: /* <<< i neeeed reset trace of test to first line of test Line16 :>>>*/ 
Line17:      } 
Line18:      } 
Line19:  there are about 400 lines codes like Up at under of this line } 
Line20:} 

我的目标是15行 - 如果我加一个return在示踪跳转到第17行 - 我需要示踪跳转到行2 对不起,我的英语不好(我搜索查找原因,解决它,但我不能找到anythings)

+0

它可能是你正在寻找的“返回”关键字?我不确定我是否理解这个问题 –

+0

为什么编辑我的问题?我没有neeed它每个人都知道它 - 如果我在如果如果我想要从第三如果我打破目前如果和我的踪迹去下一个 –

+1

这是可怕的。重构你的代码。 – Blorgbeard

回答

3

为了从一个函数使用return“破发”:

public void test(bool start) 
{ 
    if (start) //do something; 
    else // i use else for update with help other code and... forget it 
    { 
    //do somethings (it is loop) 
    pleas reset trace of test to first line of test 
    return; // This ends the method, and returns to the caller 
    } 
} 
+0

Retorn不是好方法,因为我有很多,如果在它约400行代码 –

+2

@ehsanwwe代码的行数不应该是一个问题 - 只需将'return'放在您想要结束的位置执行。 – dasblinkenlight

+0

tnx评论:*我测试它,只是示踪剂terurn最后如果例如3行在上,我跳过如果在上面,如果我想从第一行重置(我需要返回整个) –