// Fills a Stack with the contents of a particular collection. The items are // pushed onto the stack in the same order they are read by the enumerator. public Stack(IEnumerable <T> collection) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } _array = EnumerableHelpers.ToArray(collection, out _size); }
// Fills a Queue with the elements of an ICollection. Uses the enumerator // to get each of the elements. // /// <include file='doc\Queue.uex' path='docs/doc[@for="Queue.Queue3"]/*' /> public Queue(IEnumerable <T> collection) { if (collection == null) { throw new ArgumentNullException("collection"); } _array = EnumerableHelpers.ToArray(collection, out _size); _tail = (_size == _array.Length) ? 0 : _size; }
// Fills a Queue with the elements of an ICollection. Uses the enumerator // to get each of the elements. public Queue(IEnumerable <T> collection) { ArgumentNullException.ThrowIfNull(collection); _array = EnumerableHelpers.ToArray(collection, out _size); if (_size != _array.Length) { _tail = _size; } }
// Fills a Stack with the contents of a particular collection. The items are // pushed onto the stack in the same order they are read by the enumerator. public Stack(IEnumerable <T> collection) { if (collection == null) { throw new ArgumentNullException("collection"); } int length; _array = EnumerableHelpers.ToArray(collection, out length); _size = length; }
// Fills a Queue with the elements of an ICollection. Uses the enumerator // to get each of the elements. public Queue(IEnumerable <T> collection) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } _array = EnumerableHelpers.ToArray(collection, out _size); if (_size != _array.Length) { _tail = _size; } }
/// <summary> /// Reserves a region if the items' count can be predetermined; otherwise, adds the items to this builder. /// </summary> /// <param name="items">The items to reserve or add.</param> /// <returns><c>true</c> if the items were reserved; otherwise, <c>false</c>.</returns> /// <remarks> /// If the items' count is predetermined to be 0, no reservation is made and the return value is <c>false</c>. /// The effect is the same as if the items were added, since adding an empty collection does nothing. /// </remarks> public bool ReserveOrAdd(IEnumerable <T> items) { int itemCount; if (EnumerableHelpers.TryGetCount(items, out itemCount)) { if (itemCount > 0) { Reserve(itemCount); return(true); } } else { AddRange(items); } return(false); }
// Fills a Stack with the contents of a particular collection. The items are // pushed onto the stack in the same order they are read by the enumerator. public Stack(IEnumerable <T> collection) { ArgumentNullException.ThrowIfNull(collection); _array = EnumerableHelpers.ToArray(collection, out _size); }