1、使用Goto来控制方法循环执行多次
private void Test_With_goto(int count)
{
int i = 0;
label1:
Console.WriteLine("方法执行,存在goto");
i++;
if (i < count)
{
goto label1;
}
}
2、使用递归来控制方法循环执行多次
private void Test_Without_goto(int count)
{
Console.WriteLine("方法执行,递归替代goto");
count--;
if (count == 0)
{
return;
}
Test_Without_goto(count);
}
如需学习winform开发,请关注本人博客专栏winform从入门到精通开发教程