我用的是 C # 。我有一份物品清单。我使用 foreach
循环遍历每个项目。在我的 foreach
中,我有很多 if
语句检查一些东西。如果这些 if
语句中的任何一个返回 false,那么我希望它跳过该项,转到列表中的下一项。后面的所有 if
语句都应该被忽略。我尝试使用 break,但 break 退出了整个 foreach
语句。
这是我目前拥有的:
foreach (Item item in myItemsList)
{
if (item.Name == string.Empty)
{
// Display error message and move to next item in list. Skip/ignore all validation
// that follows beneath
}
if (item.Weight > 100)
{
// Display error message and move to next item in list. Skip/ignore all validation
// that follows beneath
}
}
谢谢