Push and pop value : Stack « Data Structure « C# / CSharp Tutorial






using System; 
using System.Collections; 
  
class StackDemo { 
 
 
  public static void Main() { 
    Stack st = new Stack(); 
 
    st.Push(1); 
    st.Push(2); 

    foreach(int i in st) 
      Console.Write(i + " "); 
 
    st.Push(1); 
 
    Console.Write("stack: "); 
    foreach(int i in st) 
      Console.Write(i + " "); 
 
    Console.WriteLine();         


    Console.Write("Pop -> "); 
    int a = (int) st.Pop(); 
    Console.WriteLine(a); 
 
    Console.Write("stack: "); 
    foreach(int i in st) 
      Console.Write(i + " "); 
 
    Console.WriteLine();         

  } 
}
2 1 stack: 1 2 1
Pop -> 1
stack: 2 1








11.39.Stack
11.39.1.Push and pop value
11.39.2.Clear a stack
11.39.3.Pop and Peek
11.39.4.Stack And Queue
11.39.5.Stack and Queue are both ICollection