Remove and return the object at the top of the Stack in CSharp
Description
The following code shows how to remove and return the object at the top of the Stack.
Example
using System;/*w w w . j av a 2s . 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");
Console.WriteLine(numbers.Pop());
Console.WriteLine(numbers.Peek());
Console.WriteLine(numbers.Pop());
}
}
The code above generates the following result.