Home  |  Delphi .net Home  |  System.Collections.Stack  |  Push Method
  
Push  
Method  
Add an item to the top of the current Stack
Stack Class
System.Collections NameSpace
CF1.  Procedure Push ( Value : Object ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
A new item Valu is added to the top of the stack. It will be the first to be removed if the stack is now processed.
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('Removing 2 Stack items');
  MyStack.Pop;
  MyStack.Pop;

  // Add 2 more Stack items
  Console.WriteLine('Adding 2 new Stack items');
  MyStack.Push('New item 1');
  MyStack.Push('New item 2');

  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
  
   Removing 2 Stack items
   Adding 2 new Stack items
  
   Stack now contains :
  
   New item 2
   New item 1
   First
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author