【发布时间】:2013-05-10 14:20:17
【问题描述】:
我有这样的事情:
static int cantryagain=0;
private void myfunction(){
if (cantryagain==0)
{
if(variableA=1)
{
//do my stuff
//ta daaaa
}
else
{
//do something magical that will help make variableA=1 but
//if the magic doesnt work i only want it to try once.
tryagain();
}
}
}
private void tryagain
{
myfunction();
cantryagain=1; //to make sure the magic only happens once, but
//obviously it never gets here as it does
//myfunction again before it ever can...
}
我知道这段代码非常糟糕。我对 c# 还很陌生。
我怎样才能正确地做出这样的事情?
【问题讨论】:
-
这不会编译并执行您正在尝试的操作,请查看 while 循环
-
这就像一道作业题
-
顺便说一句,我建议您阅读
bool类型 -
@ClintonWard - 不一定不鼓励家庭作业问题。见meta.stackexchange.com/a/10812/191410
标签: c# if-statement