Convert Stack to array in CSharp

Description

The following code shows how to convert Stack to array.

Example


// w  w  w .ja  v  a 2  s.c  om
using System;
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[] arr = numbers.ToArray();
        foreach( string number in arr)
        {
            Console.WriteLine(number);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary