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)); }
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)); }