0
I was having an error in a business rule, and when investigating, I arrived at the following code snippet, the intention of which is to verify that all the processes on a list are active:
return processos.All(proc => proc.Ativo)
While debugging, I discovered that processos
had zero elements. It is easy to correct, just change the conditional to:
return processos.Any() && processos.All(proc => proc.Ativo)
However, the documentation official states that the .All
:
Determines whether all elements of a sequence meet a condition.
If a list is empty, how can all elements meet a condition? Or I have some misconception?
I made a playable example on Rextester.
Interestingly you can invert the Portuguese in order to answer the question. If the list is empty there is no element, so the
.All
test if none meets the condition. And in fact none meets. D– Isac