Beispiel #1
0
        /// <summary>
        /// Copies the elements of the <see cref="PriorityQueue{T}"/> to an existing one-dimensional <see cref="Array"/>, starting at a particular array index.
        /// </summary>
        /// <param name="array">The one-dimensional <see cref="Array"></see> that is the destination of the elements
        /// copied from the <see cref="PriorityQueue{T}"/>. The <see cref="Array"></see> must have zero-based indexing.</param>
        /// <param name="index">The zero-based index in <paramref name="array"/> at which copying begins.</param>
        public void CopyTo(T[] array, int index)
        {
            // check parameters
            CollectionImpl.CheckCopyToParameters(array, index, m_size);

            // copy each item to the destination array
            foreach (T item in this)
            {
                array[index++] = item;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Copies the elements of the <see cref="PriorityQueue{T}"/> to an existing one-dimensional <see cref="Array"/>, starting at a particular array index.
        /// </summary>
        /// <param name="array">The one-dimensional <see cref="Array"></see> that is the destination of the elements
        /// copied from the <see cref="PriorityQueue{T}"/>. The <see cref="Array"></see> must have zero-based indexing.</param>
        /// <param name="index">The zero-based index in <paramref name="array"/> at which copying begins.</param>
        void ICollection.CopyTo(Array array, int index)
        {
            // check parameters
            CollectionImpl.CheckCopyToParameters(array, index, m_size);

            try
            {
                // copy each item to the destination array
                foreach (T item in this)
                {
                    array.SetValue(item, index++);
                }
            }
            catch (InvalidCastException)
            {
                // convert exception thrown by Array.SetValue to the type that ICollection.CopyTo is expected to throw.
                throw new ArgumentException("The type of the source collection cannot be cast automatically to the type of the destination array.", nameof(array));
            }
        }