I would like to create a test such that if a certain property is true for any Object in a list, the result would be true.
Normally the way I would do it is:
foreach (Object o in List)
{
if (o.property)
{
myBool = true;
break;
}
myBool = false;
}
So my question is: Is there a more concise way of doing the same task? Maybe something similar to the following:
if (property of any obj in List)
myBool = true;
else
myBool = false;
Use LINQ and a Lambda Expression.
myBool = List.Any(r => r.property)