Both the List.TrueForAll method and the IEnumerable.All method can be used to check if all list elements satisfy a given
condition in a collection. However, List.TrueForAll can be faster than IEnumerable.All for List objects. The
performance difference may be minor for small collections, but for large collections, it can be noticeable.
It is important to enable this rule with caution, as performance outcomes can vary significantly across different runtimes. Notably, the performance improvements in .NET 9 have brought
All closer to the performance of collection-specific TrueForAll methods in most scenarios.
Applies to
What is the potential impact?
We measured at least 4x improvement both in execution time. For more details see the Benchmarks section from the More
info tab.