Skip to content

Commit 065b524

Browse files
Copilotstephentoub
andcommitted
Revert ICollection<TSource> check removal in Any() method
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 74bc8d1 commit 065b524

File tree

1 file changed

+5
-0
lines changed
  • src/libraries/System.Linq/src/System/Linq

1 file changed

+5
-0
lines changed

src/libraries/System.Linq/src/System/Linq/AnyAll.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public static bool Any<TSource>(this IEnumerable<TSource> source)
1515
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.source);
1616
}
1717

18+
if (source is ICollection<TSource> gc)
19+
{
20+
return gc.Count != 0;
21+
}
22+
1823
if (!IsSizeOptimized && source is Iterator<TSource> iterator)
1924
{
2025
int count = iterator.GetCount(onlyIfCheap: true);

0 commit comments

Comments
 (0)