I am using C#. I have a list of items. I loop through each item using a foreach
. Inside my foreach
I have a lot of if
statements checking some stuff. If any of these if
statements returns a false then I want it to skip that item and go to the next item in the list. All if
statements that follow should be ignored. I tried using a break but a break exits the whole foreach
statement.
This is what I currently have:
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
}
}
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…