Action collection : Generic Collection : Generic C# Examples


C# Examples » Generic » Generic Collection »

 

Action collection









    
using  System;
using  System.Collections;
using  System.Collections.Generic;
using  System.Collections.ObjectModel;
using  System.Text;

class  ActionCollection<T>  :  Collection<T>
{
        private  Action<T>  action;

        public  ActionCollection(Action<T>  action)
        {
                this.action  =  action;
        }

        protected  override  void  InsertItem(int  index,  T  item)
        {
                action(item);
                base.InsertItem(index,  item);
        }
}


public  class  MainClass
{
        public  static  void  Main()
        {
                ActionCollection  <string>  ac  =  new  ActionCollection<string>(Console.WriteLine);
                ac.Add("console");
        }
}
    
   
  
   



Output

console


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Generic
» Generic Collection