From 8be41181b4d321e62c91a008b69a8761b831be0d Mon Sep 17 00:00:00 2001 From: wrkettlitz Date: Thu, 5 Mar 2020 17:50:38 +0100 Subject: [PATCH] IReadOnlyCollection does not implement ICollection --- src/libraries/System.Linq/src/System/Linq/AnyAll.cs | 5 +++++ 1 file changed, 5 insertions(+) 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()) {