What differentiates Delegates Beyond Name/Signature

B

Bob Johnson

It appears to me that the only things that differentiates any delegates is
(1) the type name, and (2) the signature (return type or void, and
parameters). Is this true?

Take, for instance, the Predicate<T> delegate in the bcl. It is a required
parameter of the List<T>.Find() method.
Here is its signature:
public delegate bool Predicate<T> (T obj)

Is there anything inherently different about that Predicate<T> delegate than
a delegate that I define, with the same signature?...
public delegate bool MyPredicate<T> (T obj)


I understand that when I declare a delegate, the compiler creates a sealed
class on my behalf, that makes use of the delegate signature (type name,
parameters, etc) that I supply. Is there anything - beyond the type name
(Predicate vs MyPredicate) - in that sealed class that differentiates these
two delegates (Predicate vs MyPredicate) once the app is compiled?

I suspect there is no difference (please enlighten me if I'm wrong).
Consequently, a quick followup question (asked 3 different ways):
Is the value of having many pre-defined delegates mostly in the _name_ of
the delegate? That is, are many delegates created simply to convey meaning
about their individual intended roles? In other words - is the only thing
that makes a Predicate<T> delegate a "predicate delegate" its type name?

Thanks.
 
J

Jon Skeet [C# MVP]

It appears to me that the only things that differentiates any delegates is
(1) the type name, and (2) the signature (return type or void, and
parameters). Is this true?

Yes.

I suspect there is no difference (please enlighten me if I'm wrong).
Consequently, a quick followup question (asked 3 different ways):
Is the value of having many pre-defined delegates mostly in the _name_ of
the delegate? That is, are many delegates created simply to convey meaning
about their individual intended roles? In other words - is the only thing
that makes a Predicate<T> delegate a "predicate delegate" its type name?

Exactly. Fortunately, you can create a delegate instance of one type
from a delegate instance of another type so long as the signatures
match.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top