为什么我会收到以下编译器错误:
//错误CS0159:没有这样的标签“lbl_proc_20”
用下面的代码:
//JUST A DUMMY CODE TO ILLUSTRATE THE CONCEPT
int a = resultOfFunction1();
int b = resultOfFunction2();
//10+ Local variables that are calculated depending on the results above
if (a < 10)
{
switch (b)
{
case 0:
//Actions for A<10, B=0, using local variables
break;
case 1:
double c = someFunction(a, b); //In real code involves calculations based on a and b
if(c > 10.0)
goto lbl_proc_20; //error CS0159: No such label 'lbl_proc_20' within the scope of the goto statement
//Actions for A<10, B=1, using local variables
break;
default:
//Actions for A<10, B=Other, using local variables
break;
}
}
else if (a < 20)
{
lbl_proc_20:
switch(b)
{
case 0:
//Actions for A<20, B=0, using local variables
break;
case 1:
//Actions for A<20, B=1, using local variables
break;
case 2:
//Actions for A<20, B=2, using local variables
break;
default:
//Actions for A<20, B=Other, using local variables
break;
}
}
else if (a < 30)
{
switch(b)
{
case 0:
//Actions for A<30, B=0, using local variables
break;
case 1:
//Actions for A<30, B=1, using local variables
break;
case 2:
//Actions for A<30, B=2, using local variables
break;
default:
//Actions for A<30, B=Other, using local variables
break;
}
}
为什么我会得到一个错误的goto语句,以及如何使其工作?
编辑:改变了样品来说明实际的代码。