Пример #1
0
        /// <summary>
        /// Remove the specified number of items
        /// from this stack.Will return `this` if
        /// count requested is larger (or equal to)
        /// current size.
        ///
        /// If not, will pop off the top of the stack
        /// and create a new `Stackable` that will then
        /// be returned.
        /// </summary>
        /// <param name="requestedCount">The number of `Stackable`
        /// items to return</param>
        /// <returns>A new `Stackable`</returns>
        public Stackable Remove(int requestedCount)
        {
            if (requestedCount - 1 >= Size())
            {
                return(this);
            }

            Stackable baseStackable = Get(0);

            if (requestedCount > 1)
            {
                List <Stackable> otherStackables = Stack.GetRange(0, requestedCount - 1);
                Stack.RemoveRange(0, requestedCount - 1);

                foreach (Stackable s in otherStackables)
                {
                    baseStackable.Add(s);
                }
            }

            UpdateCountLabel();
            baseStackable.UpdateCountLabel();
            return(baseStackable);
        }