delegate 委托的使用
来源:互联网 发布:淘宝老店新开怎么弄 编辑:程序博客网 时间:2024/06/10 14:53
从SDK中可以找到关于delegate的定义和使用方法。
个人理解,delegate是声明委托类的关键字,声明委托和声明一个类差不多, 不过,可以不用为该委托类定义什么方法或属性。
如:
delegate void SomeDelegate();
然后为该委托类创建一个实例,创建实例需要一个构造参数,该参数指定所要委托的例程的名称。
如:
SomeDelegate OneInstance = new SomeDelegate(OneMethod);
void OneMethod()
{
//Do Something
}
这样的话在执行这个委托的实例的时候就相当于实行了这个委托实例所指定的所委托的方法!
另外要注意的是,用 delegate声明的委托类的格式要和委托实例所委托的方法的声明格式一样(即返回类型,参数个数和各参数类型要一致)。
如:
delegate string B(int i);
实例化B委托类型,并运行委托:
B b = new B(A);
b(12); //此委托运行后将返回string型的字符串“12”
此时所委托的方法A 需要很委托类型B的返回类型以及参数类型和个数都保持一致。
如:
string A(int i)
{
//Do Something;
return i.ToString();
}
以上写的只是基本的用法。
- delegate 委托的使用
- C# 委托(delegate) 的使用
- .NET delegate 委托的使用
- C# 委托(delegate)的使用
- 委托控件的使用(Delegate Control)
- C# EventHandler and Delegate(委托的使用)
- C# EventHandler and Delegate(委托的使用)
- C# EventHandler and Delegate(委托的使用)
- C#中Delegate委托的使用
- iOS中delegate(委托)的使用
- IOS -- Delegate委托 的 使用与理解
- 05.C#委托(delegate)的使用
- C# EventHandler and Delegate(委托的使用)
- C# EventHandler and Delegate(委托的使用)
- 委托Delegate使用帮助
- C#委托delegate使用
- C#的委托 delegate
- delegate委托的理解
- 在Windows2003系统中使用VBS利用cdosys.dll发送邮件
- C#.Net的常见面试试题(1)——基本概念
- 穷人为什么穷
- 40种网页常用小技巧(javascript)
- T-flash卡
- delegate 委托的使用
- 设置全屏显示的S60程序
- 在应用中调用 Wap 浏览器 并打开指定URL
- 8种没结果的爱
- 第一次发表blog
- 创业者的10大谎言
- Spring+EasyJWeb+iBatis版j2ee在线购物jpetstore系统源码发布
- 怎么设计自己的模块
- 软件混音的实现