Home  |  Delphi .net Home  |  System.Collections.Stack  |  Pop Method
  
Pop  
Method  
Remove the item from the top of the current Stack
Stack Class
System.Collections NameSpace
CF1.  Function Pop : Object;
CF : Methods with this mark are Compact Framework Compatible
Description
The last item added to the current stack is removed and returned. The Count is decremented.
Microsoft MSDN Links
System.Collections
System.Collections.Stack
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  MyStack    : System.Collections.Stack;
  Enumerator : IEnumerator;

begin
  // Create our Stack
  MyStack := Stack.Create;

  // Add entries to the Stack
  MyStack.Push('First');
  MyStack.Push('Second');
  MyStack.Push('Third');

  // Display the Stack
  Console.WriteLine('Stack contains :');
  Console.WriteLine;
  Enumerator := MyStack.GetEnumerator;
  while enumerator.MoveNext do
    Console.WriteLine(Enumerator.Current.ToString);

  Console.WriteLine;

  // Get 2 items from the Stack
  Console.WriteLine('1st item from the stack : ' +
                    MyStack.Pop.ToString);

  Console.WriteLine('2nd item from the stack : ' +
                    MyStack.Pop.ToString);

  Console.WriteLine;

  // Display the Stack again
  Console.WriteLine('Stack now contains :');
  Console.WriteLine;
  Enumerator := MyStack.GetEnumerator;
  while enumerator.MoveNext do
    Console.WriteLine(Enumerator.Current.ToString);

  Console.Readline;
end.
   Stack contains :
  
   Third
   Second
   First
  
   1st item from the stack : Third
   2nd item from the stack : Second
  
   Stack now contains :
  
   First
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author