예제 #1
0
 // 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);
 }
예제 #2
0
        // 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;
        }
예제 #3
0
파일: Queue.cs 프로젝트: mikem8361/runtime
        // 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;
            }
        }
예제 #4
0
파일: Stack.cs 프로젝트: erdomke/Frameworks
        // 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;
        }
예제 #5
0
        // 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);
        }
예제 #7
0
        // 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);
        }