C# Stack CopyTo

Description

Stack CopyTo copies the Stack to an existing one-dimensional Array, starting at the specified array index.

Syntax

Stack.CopyTo has the following syntax.


public void CopyTo(
  T[] array,
  int arrayIndex
)

Parameters

Stack.CopyTo has the following parameters.

  • array - The one-dimensional Array that is the destination of the elements copied from Stack . The Array must have zero-based indexing.
  • arrayIndex - The zero-based index in array at which copying begins.

Example


using System;//from   www. j  ava  2  s  .  co m
using System.Collections.Generic;

class Example
{
    public static void Main()
    {
        Stack<string> numbers = new Stack<string>();
        numbers.Push("one");
        numbers.Push("two");
        numbers.Push("three");
        numbers.Push("four");
        numbers.Push("five");
        string[] array2 = new string[numbers.Count * 2];
        numbers.CopyTo(array2, numbers.Count);

    }
}




















Home »
  C# Tutorial »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack