Create a Stack from a collection in CSharp
Description
The following code shows how to create a Stack from a collection.
Example
using System;//from w w w.j a v a 2 s . c o 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");
Stack<string> stack2 = new Stack<string>(numbers.ToArray());
foreach( string number in stack2 )
{
Console.WriteLine(number);
}
}
}
The code above generates the following result.