Insert an object at the top of the Stack in CSharp
Description
The following code shows how to insert an object at the top of the Stack.
Example
using System;//w ww . j a v a 2 s. c om
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");
foreach( string number in numbers )
{
Console.WriteLine(number);
}
}
}
The code above generates the following result.