Push and pop value in a generic Stack : Generic Stack « Generic « C# / CSharp Tutorial






using System;  
using System.Collections.Generic;  
   
class MainClass {  
  public static void Main() {  
    Stack<string> st = new Stack<string>();  
  
    st.Push("One");  
    st.Push("Two");  
    st.Push("Three");  
    st.Push("Four");  
    st.Push("Five");  
 
    while(st.Count > 0) { 
      string str = st.Pop(); 
      Console.Write(str + " "); 
    } 
 
    Console.WriteLine();  
  }  
}
Five Four Three Two One








18.4.Generic Stack
18.4.1.Use generic Statck to store your own class
18.4.2.Generic Stack based on generic Array
18.4.3.Push and pop value in a generic Stack