예제 #1
0
        public static int Count <TEnumerable, TEnumerator, TSource>(this TEnumerable source)
            where TEnumerable : IEnumerable <TSource>
            where TEnumerator : IEnumerator <TSource>
        {
            if (source == null)
            {
                ThrowSourceNull();
            }

            return(CountCache <TEnumerable, TEnumerator, TSource> .count(source));

            void ThrowSourceNull() => throw new ArgumentNullException(nameof(source));
        }
예제 #2
0
        public static long Count <TEnumerable, TSource>(this TEnumerable source) where TEnumerable : IEnumerable <TSource>
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (source is ICollection <TSource> collection)
            {
                return(collection.Count);
            }

            if (source is IReadOnlyCollection <TSource> readOnlyCollection)
            {
                return(readOnlyCollection.Count);
            }

            return(CountCache <TEnumerable, TSource> .count(source));
        }