Use generic Statck to store your own class : Generic Stack : Generic C# Examples


C# Examples » Generic » Generic Stack »

 

Use generic Statck to store your own class









    
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";
      }
        
}
    
   
  
   



Output

Popped from stack: my class


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Generic
» Generic Stack