private void IntStackTestCopyTo(IStack <int> st) { int[] arr = { 1, 2, 3, 4, 5 }; int[] arr_to_copy = new int[5]; arr_to_copy[0] = 1; arr_to_copy[4] = 5; st.Clear(); st.Push(4); st.Push(3); st.Push(2); st.CopyTo(arr_to_copy, 1); Assert.AreEqual(arr, arr_to_copy); st.Push(6); var ex = Assert.Throws <ArgumentException>(() => st.CopyTo(arr_to_copy, 1)); Assert.That(ex.Message, Is.EqualTo("The number of elements in the source Stack<T> is greater than the available space from arrayIndex to the end of the destination array.")); }
/// <summary> /// Copies the elements of the <see cref="ICollection" /> to an <see cref="Array" />, starting at a particular /// <see cref="Array" /> index. /// </summary> /// <param name="array"> /// The one-dimensional <see cref="Array" /> that is the destination of the elements copied from /// <see cref="ICollection" />. The <see cref="Array" /> 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( Array array, int index) => internalStack.CopyTo( array, index);
/// <inheritdoc /> public void CopyTo(Array array, int index) { _stack.CopyTo(array, index); }