如何解决返回上一个循环?
| 我如何在另一个循环上返回? for (int index = MIN_DIAGNOSIS; index <= MAX_DIAGNOSIS; index++)
{
foreach (RepeaterItem ri1 in GeneralRepeater.Items)
{
int iItemIndex = ri1.ItemIndex;
var myDDL = GeneralRepeater.Items[iItemIndex].FindControl(\"derp\");
MyPoc.Diagnoses.Diagnoses[index] = new PatientDiagnosis(/*snip*/);
return index;
//error \'PatientPlanOfCare.cmdSave_Click(object,System.EventArgs)\'
//returns void,a return keyword must not be followed by
//an object expression
}
}
break;
解决方法
只需中断内部循环并在主循环上使用所需的变量即可。
for (int index = PocDiagnoses.MIN_DIAGNOSIS; index <= PocDiagnoses.MAX_DIAGNOSIS; index++)
{
foreach (RepeaterItem ri1 in GeneralRepeater.Items)
{
int iItemIndex = ri1.ItemIndex;
DropDownList myDDL = (DropDownList)GeneralRepeater.Items[iItemIndex].FindControl(\"GeneralDDL\");
MyPoc.Diagnoses.Diagnoses[index] = new PatientDiagnosis(myDDL.SelectedValue,new SynergyOnSetDate(new System.DateTime(Year,Month,Day)),\"01/02/2011\");
break;
}
// Check the index variable here.
}
,就像评论一样,很难说出您要做什么。
根据您注释中的错误消息,此代码正在以返回void的方法执行,这意味着您的return
语句后不应有index
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。