Michal Czardybon
Michal Czardybon

Reputation: 2865

Does "delegate" mean a type or an object?

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:

Some other uses of "delegate" word in MSDN in the second meaning:

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.

Upvotes: 1

Views: 512

Answers (2)

Marcello Belguardi
Marcello Belguardi

Reputation: 101

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);

Upvotes: 0

John Saunders
John Saunders

Reputation: 161801

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

Upvotes: 9

Related Questions