How can I restart a foreach
loop in C#??
For example:
Action a;
foreach(Constrain c in Constrains)
{
if(!c.Allows(a))
{
a.Change
void Main()
{
IEnumerable cons;
SomeObject a;
while(!TryChangeList(cons, a)) { }
}
// the name tryChangeList reveals the intent that the list will be changed
private bool TryChangeList(IEnumerable constrains, SomeObject a)
{
foreach(var con in constrains)
{
if(!c.Allows(a))
{
a.Change();
return false;
}
}
return true;
}