diff --git a/src/libraries/System.Linq/src/System/Linq/AnyAll.cs b/src/libraries/System.Linq/src/System/Linq/AnyAll.cs index f97526a40cdff9..97f193a31429e4 100644 --- a/src/libraries/System.Linq/src/System/Linq/AnyAll.cs +++ b/src/libraries/System.Linq/src/System/Linq/AnyAll.cs @@ -20,6 +20,10 @@ public static bool Any(this IEnumerable source) { return collectionoft.Count != 0; } + + if (source is IReadOnlyCollection readOnlyCollection) + return readOnlyCollection.Count != 0; + else if (source is IIListProvider listProv) { // Note that this check differs from the corresponding check in @@ -38,6 +42,7 @@ public static bool Any(this IEnumerable source) { return collection.Count != 0; } + using (IEnumerator e = source.GetEnumerator()) {