Runtime: Performance of LINQ .Any() - type check to leverage .Count property?

Created on 2 Oct 2018  路  2Comments  路  Source: dotnet/runtime

In the .Any() method here:
https://github.com/dotnet/corefx/blob/e043326e204a9566ee26403b522cf95cda2d54ee/src/System.Linq/src/System/Linq/AnyAll.cs#L18:L21

would it make sense to check for IReadOnlyCollection and call Count in order to avoid the enumerator instantiation?

Most helpful comment

Oh well, it would appear there is high demand for that. ;) I'll close this one and I promise to properly use the search next time.

All 2 comments

Oh well, it would appear there is high demand for that. ;) I'll close this one and I promise to properly use the search next time.

Was this page helpful?
0 / 5 - 0 ratings