什么是c#中的委托?请以简单的方式解释,请举例说明。 [英] what is a delegate in c# ?Explain in simple way with example please.

查看:108
本文介绍了什么是c#中的委托?请以简单的方式解释,请举例说明。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c#中的委托是什么?请以简单的方式解释一下。

what is a delegate in c# ?Explain in simple way with example please.

推荐答案

这里有一个很好的解释,例如:

http://www.tutorialspoint.com/csharp/csharp_delegates.htm [ ^ ]
Here you are a good explanation with example:
http://www.tutorialspoint.com/csharp/csharp_delegates.htm[^]


本质上它是一个指针到一个函数:它允许你将一个函数的地址存储在一个变量中,然后再调用它,而不必确切地知道你在那个时候调用了什么函数。



这允许您在不更改代码的情况下更改代码!

例如,您可能有一些代码从yoru数据库输出一页信息。如果您使用委托,您可以通过传递一个不同的输出功能来实现屏幕或打印机,而不需要改变实际的方法。



还有很多东西,你需要正确阅读它: http://msdn.microsoft.com/en-gb/library/ms173171.aspx [ ^ ]值得一读。
In essence it's a "pointer to a function": it allows you to store the address of a function in a variable and then call it later, without having to know exactly what function you are calling at that point.

This allows you to change what code does without changing the code!
For example, you might have a bit of code which outputs a page of information from yoru database. If you use a delegate, you can make it work to the screen or a printer without changing the actual method at all, by passing it a different "output function" which does the actual output.

There is a lot more to it than that, and you need to read up on it properly: http://msdn.microsoft.com/en-gb/library/ms173171.aspx[^] is worth reading before you submit your homework.


见下面的链接



初学者代表教程 [ ^ ]



http://www.tutorialspoint.co m / csharp / csharp_delegates.htm [ ^ ]



http://msdn.microsoft.com/en-in/library/aa288459(v=vs.71).aspx [ ^ ]
see below link

Delegate Tutorial for Beginners[^]

http://www.tutorialspoint.com/csharp/csharp_delegates.htm[^]

http://msdn.microsoft.com/en-in/library/aa288459(v=vs.71).aspx[^]


这篇关于什么是c#中的委托?请以简单的方式解释,请举例说明。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆