Here is the GetRange :
public List<T> GetRange(int index, int count) { if (index < 0) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } if (count < 0) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } if ((this._size - index) < count) { ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); } List<T> list = new List<T>(count); Array.Copy(this._items, index, list._items, 0, count);
And this is Take Implementation
public static IEnumerable<TSource> Take<TSource>(this IEnumerable<TSource> source, int count) { if (source == null) { throw Error.ArgumentNull("source"); } return TakeIterator<TSource>(source, count); } private static IEnumerable<TSource> TakeIterator<TSource>(IEnumerable<TSource> source, int count) { if (count > 0) { foreach (TSource iteratorVariable0 in source) { yield return iteratorVariable0; if (--count == 0) { break; } } } }
Plus a ToList that just does:
public static List<TSource> ToList<TSource>(this IEnumerable<TSource> source) { if (source == null) { throw Error.ArgumentNull("source"); } return new List<TSource>(source); }
And the List constructor:
public List(IEnumerable<T> collection) { if (collection == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection); } ICollection<T> is2 = collection as ICollection<T>; if (is2 != null) { int count = is2.Count; if (count == 0) { this._items = List<T>._emptyArray; } else { this._items = new T[count]; is2.CopyTo(this._items, 0); this._size = count; } } else { this._size = 0; this._items = List<T>._emptyArray; using (IEnumerator<T> enumerator = collection.GetEnumerator()) { while (enumerator.MoveNext()) { this.Add(enumerator.Current); } } } }
You can immediately notice how GetRange cheaper GetRange Take
source share