I want to check if all items of a list meet a set of criteria:
bool AreValid(list<string> vals)
{
bool allValid=true;
foreach(string val in vals)
{
if(!condition1)
...
allValid=false;
else if(!condition2)
...
allValid=false;
}
return allValid;
}
The reason I can't use LINQ All()
is that for each failed condition I'm doing some job.
is it safe to set allValid
as true
by default?