我正在使用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
}
}
谢谢
if
语句级联一样。 - Steve Townsend