Get object at the top of the Stack without removing it in CSharp
Description
The following code shows how to get object at the top of the Stack without removing it.
Example
/*from w w w. ja v a2 s. c o m*/
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");
Console.WriteLine(numbers.Peek());
Console.WriteLine(numbers.Peek());
Console.WriteLine(numbers.Peek());
}
}
The code above generates the following result.