Stack.Peek() : Stack « System.Collections « C# / C Sharp by API






Stack.Peek()

  
 using System;
 using System.Collections;
    public class TesterStackDemo{
       public void Run(){
           Stack intStack = new Stack();
           for (int i = 0;i<8;i++){
               intStack.Push(i*5);
           }
           Console.Write( "intStack values:\t" );
           DisplayValues( intStack );
           Console.WriteLine( "\n(Pop)\t{0}",intStack.Pop() );
           Console.Write( "intStack values:\t" );
           DisplayValues( intStack );
           Console.WriteLine( "\n(Pop)\t{0}",intStack.Pop() );
           Console.Write( "intStack values:\t" );
           DisplayValues( intStack );
           Console.WriteLine( "\n(Peek)   \t{0}",intStack.Peek() );
           Console.Write( "intStack values:\t" );
           DisplayValues( intStack );

       }
       public static void DisplayValues(IEnumerable myCollection ){
            foreach (object o in myCollection){
                Console.WriteLine(o);
            }
        }
        static void Main()
        {
          TesterStackDemo t = new TesterStackDemo();
          t.Run();
        }
    }

   
    
  








Related examples in the same category

1.Stack.Count
2.Stack.ToArray()