什么是代表?
在 stackoverflow 上搜索答案时,许多代码示例使用代表。这些是什么?他们如何运作?何时、为何以及如何使用它们?请给出一些简单的代码示例
Possible Duplicates:
C# - Can someone tell me why and where I should use delegates?
C# Delegates Real World Usage
While searching for answers here on stackoverflow, many of the code examples use Delegates. What are they? How they work? when, why and how to use them? Please give some simple code examples
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Objective-C 委托是简单的抽象模式。 WikiPedia 对此进行了详细描述。
Objective-C delegates are simple abstraction pattern. It's described very on WikiPedia.
在 C# 中,委托不仅仅是一件事:
Jon Skeet 的有关事件和代表的文章更深入地介绍了这一点。
A delegate is more than one thing in C#:
Jon Skeet's article on events and delegates covers this in more depth.
代表基本上是一流的职能。
也就是说,它们是在程序中作为自己的实体独立存在的函数,而不是绑定到另一个实体(例如类)。
如果您有 C/C++ 背景,则可以将它们视为与函数指针等效的强类型 .NET。
Delegates are basically first-class functions.
That is, they are functions which stand alone as their own entities in the program, as opposed to being tied to another entity such as a class.
If you have C/C++ background, it is acceptable to think of them as a strongly-typed .NET equivalent to function pointers.
委托是一个类型安全的函数指针 - 通常用于实现抽象、回调等。
请参阅以下答案:
C# 中的委托比 C/C++ 中的函数指针更好吗?
委托有哪些优点?
委托和回调是否相同或相似?
A delegate is a typesafe function pointer - typically used to implement abstraction, callback, etc.
See these answers:
How are delegates in C# better than function pointers in C/C++?
What are the advantages of delegates?
Are delegates and callbacks the same or similar?