是否“委托”? 是指类型还是对象?
从 MSDN 阅读: “委托是一种引用方法的类型。一旦为委托分配了一个方法,它的行为就与该方法完全相同。”
那么“委托”是指类型还是对象?!
...不能两者兼而有之。 在我看来,这个词有两种不同的含义:
- 一种包含对某些指定签名的方法的引用的类型,
- 一种该类型的对象,实际上可以像方法一样调用它。
我希望使用更精确的词汇,并在第一种情况下使用“委托类型”。 我最近读了很多有关活动和代表的文章,这种模糊性多次让我感到困惑。
的第一个含义是:
- “仅当事件生成事件数据时才需要自定义事件委托”
- “委托声明定义了从类 System.Delegate 派生的类”
MSDN 中“委托”一词的一些其他用法 MSDN 中的“委托”一词的第二种含义是:
- “指定在发生某些事件时将被调用的委托”
- “委托是引用方法的对象。它们有时被描述为类型安全的” 函数指针”
你觉得怎么样?为什么微软的人引入了这种歧义?我是唯一一个在同一个词引用不同概念时遇到概念问题的人吗?
Reading from MSDN:
"A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method."
Does then "delegate" mean a type or an object?!
...It cannot be both. It seems to me that the single word is used in two different meanings:
- a type containing a reference to a method of some specified signature,
- an object of that type, which can be actually called like a method.
I would prefer a more precise vocabulary and use "delegate type" for the first case. I have been recently reading a lot about events and delegates and that ambiguity was making me confused many times.
Some other uses of "delegate" word in MSDN in the first meaning:
- "Custom event delegates are needed only when an event generates event data"
- "A delegate declaration defines a class that is derived from the class System.Delegate"
Some other uses of "delegate" word in MSDN in the second meaning:
- "specify a delegate that will be called upon the occurrence of some event"
- "Delegates are objects that refer to methods. They are sometimes described as type-safe
function pointers"
What do you think? Why did people from Microsoft introduced this ambiguity? Am I the only person to have conceptual problems with different notions being referenced with the same word.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
委托类型指的是签名,而不是特定方法。 如果已分配,委托实例可能包含一个或多个方法引用。
所以委托类型是:
委托实例是:
委托实例赋值可能是:
A delegate type refers to a signature, not a specific method. A delegate instance, may, if assigned, contain one or more methods references.
So the delegate type is:
The delegate instance is:
The delegate instance assignment may be:
文本中双向使用了“委托”一词; 作为类型和类型的实例。
它应该说“委托类型是引用方法的类型。一旦为委托实例分配了一个方法,它的行为就与该方法完全相同。”
The text is using the word
delegate
both ways; as a type and as an instance of the type.It should say "A delegate type is a type that references a method. Once a delegate instance is assigned a method, it behaves exactly like that method."