Esempio n. 1
0
        /// <summary>
        /// Moves elements from this <see cref="Segment{T}"/> to another from and to the specified indexes. Moved elements are replaced by default values in the source, and override existing elements in the destination.
        /// </summary>
        /// <param name="destination">The destination <see cref="Segment{T}"/> object.</param>
        /// <param name="toIndex">The zero-based index at which the new elements should be moved in the destination.</param>
        /// <param name="fromIndex">The zero-based index in the source from which elements should be moved.</param>
        /// <param name="count">The number of elements to move.</param>
        public void MoveTo(ISegment <T> destination, int toIndex, int fromIndex, int count)
        {
            Contract.RequireNotNull(destination, out Segment <T> Destination);

            Debug.Assert(toIndex >= 0 && toIndex <= destination.Count);
            Debug.Assert(fromIndex >= 0 && fromIndex <= Count);
            Debug.Assert(count >= 0);
            Debug.Assert(toIndex + count <= destination.Count);
            Debug.Assert(fromIndex + count <= Count);

            for (int i = 0; i < count; i++)
            {
                Destination.Content[toIndex + i] = Content[fromIndex + i];
            }

            for (int i = fromIndex; i < Count - count; i++)
            {
                Content[i] = Content[i + count];
            }

            for (int i = Count - count; i < Count; i++)
            {
                Content[i] = default(T) !;
            }

            Count -= count;

            AssertInvariant();
            Destination.AssertInvariant();
        }