CSharp · Console
using System;
using System.Collections.Generic;
public class Program
{
public delegate void OnAddEventHandler(object item);
public class AddEventArgs : EventArgs
{
public object item { get; set; }
}
public class MyList<T> : List<T>
{
public event OnAddEventHandler OnAdd;
public new void Add(T item)
{
base.Add(item);
if (OnAdd != null)
{
OnAdd(item);
}
}
}
public static void Main()
{
MyList<string> lst = new MyList<string>();
lst.OnAdd += (item) => {
Console.WriteLine("new item added: " + item);
};
lst.Add("test");
}
}