示例#1
0
        public static TSource[] ToArray <TSource>(this IEnumerable <TSource> source)
        {
            if (source == null)
            {
                throw Error.ArgumentNull("source");
            }
            IIListProvider <TSource> arrayProvider = source as IIListProvider <TSource>;

            return(arrayProvider != null?arrayProvider.ToArray() : EnumerableHelpers.ToArray(source));
        }
示例#2
0
文件: Buffer.cs 项目: jnm2/corefx
        /// <summary>
        /// Fully enumerates the provided enumerable and stores its items into an array.
        /// </summary>
        /// <param name="source">The enumerable to be store.</param>
        internal Buffer(IEnumerable <TElement> source)
        {
            IIListProvider <TElement> iterator = source as IIListProvider <TElement>;

            if (iterator != null)
            {
                TElement[] array = iterator.ToArray();
                _items = array;
                _count = array.Length;
            }
            else
            {
                _items = EnumerableHelpers.ToArray(source, out _count);
            }
        }
        public IGrouping <TKey, TElement>[] ToArray()
        {
            IIListProvider <IGrouping <TKey, TElement> > lookup = Lookup <TKey, TElement> .Create(_source, _keySelector, _elementSelector, _comparer);

            return(lookup.ToArray());
        }