Removes the element at the top of the stack and returns it. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:Stack

Description

Removes the element at the top of the stack and returns it.

Demo Code


using System;/*from  ww  w.j  av  a  2  s.  c o m*/

public class Main{
        /// <summary>
      /// Removes the element at the top of the stack and returns it.
      /// </summary>
      /// <param name="stack">The stack where the element at the top will be returned and removed.</param>
      /// <returns>The element at the top of the stack.</returns>
      public static System.Object Pop(System.Collections.ArrayList stack)
      {
         System.Object obj = stack[stack.Count - 1];
         stack.RemoveAt(stack.Count - 1);

         return obj;
      }
}

Related Tutorials