using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 泛型委托
{
delegate void StackEventHandler<T,U>(T sender,U eventArgs); //定义委托
//delegate void BinaryOp (int x, int y); //非泛型定义委托
class Stack<T>
{
public class StackEventArgs : EventArgs
{ }
public event StackEventHandler<Stack<T>, StackEventArgs> stackEvent; //定义事件
//public event BinaryOp eventArgs; //定义事件
public virtual void OnStackChanged(StackEventArgs e)
{
stackEvent(this, e);
}
}
class SampleClass
{
public void HandleStackChange<T>(Stack<T> stack, Stack<T>.StackEventArgs args)
{
}
}
class Program
{
public static void Test()
{
Stack<double> s = new Stack<double>(); //泛型
SampleClass o = new SampleClass(); //对象实例化
s.stackEvent += o.HandleStackChange; //注册事件
}
static void Main(string[] args)
{
Test();
Console.ReadKey();
}
}
}
转载于:https://www.cnblogs.com/cpcpc/archive/2010/05/04/2123126.html