5
On a list, I have 12 records (hypothetical) and there is a field called ValorCampoFlag
, where this field receives 1 or null
, for example. If I do a validation on it and the result if there is at least one with value 1, I should use Any
or All
?
minhaVarBool = minhaLista.All(l => l.ValorCampoFlag == 1);
Or so:
minhaVarBool = minhaLista.Any(l => l.ValorCampoFlag == 1);
What strategy should I use for this type of result, i.e., set a boolean variable.
The list brings me several records and just have one in this condition to set the variable.
The 'Any' option also has better performance, because when finding the first item in the list that meets the condition it for the enumeration process, while All always checks all items in the list.
– Julio Borges