Use generic Statck to store your own class : Generic Stack « Generic « C# / CSharp Tutorial






using System;        
using System.Collections.Generic;



class MainClass
{
    public static void Main(string[] args)
    {
        // Create and use a Stack of Assembly Name objects
        Stack<MyClass> stack = new Stack<MyClass>();

        stack.Push(new MyClass());

        MyClass ass3 = stack.Pop();

        Console.WriteLine("\nPopped from stack: {0}", ass3);

    }
}
class MyClass {
    
   public override string ToString(){
    
      return "my class";
   }
    
}
Popped from stack: my class








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