help

wsmfighter2002 2004-04-01 04:14:04
c#中的委托delegate是怎么回事啊,能不能给我讲一下,在次深表感谢,敬礼!!!
最好有例子,看了msdn还是不很明白。
...全文
35 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
CMIC 2004-04-01
  • 打赏
  • 举报
回复
这个介绍很详细 C#中的委托 lotusswan(原作)
http://www.csdn.net/develop/read_article.asp?id=21901
polarlm 2004-04-01
  • 打赏
  • 举报
回复
using System;

class CSDelegateExample1
{
// define the delegate type
delegate void TestDelegate(String str);

void WriteString(String str)
{
Console.WriteLine(str);
}

public CSDelegateExample1()
{
// declare and instantiate the delegate
TestDelegate td = new TestDelegate(WriteString);

// now we can call it
td("This string will be written to the console.");
}

static void Main(string[] args)
{
new CSDelegateExample1();
}
}
SimerJoe 2004-04-01
  • 打赏
  • 举报
回复
个人理解:
委托:
例如,把第2个方法作为一个参数传给第1个方法。
void TP
{
//代码
}

Thread NewThred=new Thread();
Thread.Start(TP); //警告
等价于:

delegate dTP()=new dTP(TP)
Thread.Start(dTP)

其强大之处在于可以实现多路广播委托,既可以将多个对象的多个方法放在委托里面,从而对事件和多线程提供很好的支持。(想想C++里的函数指针。)

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧