是否“委托”? 是指类型还是对象?

发布于 2024-07-28 18:17:56 字数 607 浏览 3 评论 0原文

从 MSDN 阅读: “委托是一种引用方法的类型。一旦为委托分配了一个方法,它的行为就与该方法完全相同。”

那么“委托”是指类型还是对象?!

...不能两者兼而有之。 在我看来,这个词有两种不同的含义:

  1. 一种包含对某些指定签名的方法的引用的类型,
  2. 一种该类型的对象,实际上可以像方法一样调用它。

我希望使用更精确的词汇,并在第一种情况下使用“委托类型”。 我最近读了很多有关活动和代表的文章,这种模糊性多次让我感到困惑。

的第一个含义是:

  • “仅当事件生成事件数据时才需要自定义事件委托”
  • “委托声明定义了从类 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:

  1. a type containing a reference to a method of some specified signature,
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

锦欢 2024-08-04 18:18:12

委托类型指的是签名,而不是特定方法。 如果已分配,委托实例可能包含一个或多个方法引用。

所以委托类型是:

delegate void D();

委托实例是:

D d;

委托实例赋值可能是:

d += new D (Method);

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:

delegate void D();

The delegate instance is:

D d;

The delegate instance assignment may be:

d += new D (Method);
梦里泪两行 2024-08-04 18:18:08

文本中双向使用了“委托”一词; 作为类型和类型的实例。

它应该说“委托类型是引用方法的类型。一旦为委托实例分配了一个方法,它的行为就与该方法完全相同。”

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."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文