using System.Collections.Generic;
public delegate void StackEventHandler(object source, StackEventArgs e);
static void Main(string[] args)
var stack = new GenericStack<int>();
var myStack = new StackEventHandlers();
stack.PushEvent += myStack.OnPushEvent;
stack.PopEvent += myStack.OnPopEvent;
public class StackEventHandlers
public void OnPushEvent(object source, StackEventArgs e)
Console.WriteLine($"Yay! Pushed on {e.Top}");
public void OnPopEvent(object source, StackEventArgs e)
Console.WriteLine($"Darn! Popped from {e.Top}");
public class GenericStack<T>
public event StackEventHandler PushEvent;
public event StackEventHandler PopEvent;
private readonly List<T> stack = new List<T>();
public void Push(T element)
stack.Remove(stack[_top]);
protected virtual void RaisePushEvent(int top)
PushEvent(this, new StackEventArgs(top));
protected virtual void RaisePopEvent(int top)
PopEvent(this, new StackEventArgs(top));
public class StackEventArgs : EventArgs
public int Top { get; set; }
public StackEventArgs(int top)