rspec/rules/S6603/why-dotnet.adoc
2024-10-29 15:53:02 +01:00

12 lines
1.2 KiB
Plaintext

== Why is this an issue?
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 https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-9/#collections[performance improvements in .NET 9] have brought `All` closer to the performance of collection-specific `TrueForAll` methods in most scenarios.
*Applies to*
* https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.trueforall[List]
* https://learn.microsoft.com/en-us/dotnet/api/system.array.trueforall[Array]
* https://learn.microsoft.com/en-us/dotnet/api/system.collections.immutable.immutablelist-1.trueforall[ImmutableList]
* https://learn.microsoft.com/en-us/dotnet/api/system.collections.immutable.immutablelist-1.builder.trueforall[ImmutableList.Builder]