//定义有返回值的委托
public delegate string GenricDelegate<T, S>(T title, S author);
//定义事件委托。
public delegate void GenricDelegateEnent<E,P>(E Name,P Address);
public class GenericDelegateClass<V,F>
{
//声明委托
public GenricDelegate<V, F> GdeleValue;
//声明事件委托
public event GenricDelegateEnent<V, F> GdEvent = null;
public string GetValues(V title, F author)
{
//调用委托
return GdeleValue(title, author);
}
public GenericDelegateClass()
{
}
public void InvokeEvent(V name, F address)
{
if (GdEvent != null)
{
//调用委托
GdEvent(name, address);
}
}
}
private void btnDelegate_Click(object sender, EventArgs e)
{
GenericDelegateClass<string, string> gd = new GenericDelegateClass<string, string>();
//将DelegateReturn事件梆定给GdeleValue
gd.GdeleValue = new GenricDelegate<string, string>(DelegateReturn);
//将GenericEvent事件梆定给GdEvent
gd.GdEvent += new GenricDelegateEnent<string, string>(GenericEvent<string,string>);
}
public string DelegateReturn<T,S>(T title,S author)
{
return title.ToString() + author;
}
private void GenericEvent<V, F>(V name, F address)
{
//
}
public delegate void Del<T>(T item);
public static void Notify(int i) { }
Del<int> m1 = new Del<int>(Notify);
class Stack<T>
{
T[] items;
int index;
public delegate void StackDelegate(T[] items);
}
private static void DoWork(float[] items) { }
public static void TestStack()
{
Stack<float> s = new Stack<float>();
Stack<float>.StackDelegate d = DoWork;
}
delegate void StackEventHandler<T, U>(T sender, U eventArgs);
class Stack<T>
{
public class StackEventArgs : System.EventArgs { }
public event StackEventHandler<Stack<T>, StackEventArgs> stackEvent;
protected virtual void OnStackChanged(StackEventArgs a)
{
stackEvent(this, a);
}
}
class SampleClass
{
public void HandleStackChange<T>(Stack<T> stack, Stack<T>.StackEventArgs args) { }
}
public static void Test()
{
Stack<double> s = new Stack<double>();
SampleClass o = new SampleClass();
s.stackEvent += o.HandleStackChange;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有