I'm sorry for the newbie question, but I'm a bit confused. I'm reading
about Delegats in Jesse Liberty's C# Programming book and, well, I'm
confused as to the motivation behind delegates. On the surface, they look
exactly like using interfaces in java, so why have another construct to
confuse things?

I know they work "like function pointers" but the whole reason I went to
java was to avoid pointers! And before java, I used VB, so pointers are not
something advantageous to me. And I understand delegates are how .net does
event driven coding, but why can't interfaces be used to accomplish the
samething?

Thanks for any advice.

Re: motivation behind delegates by Jon

Jon
Thu Jan 27 15:21:44 CST 2005

Flip <[remove_me]phenry_w@hotmail.com> wrote:
> I'm sorry for the newbie question, but I'm a bit confused. I'm reading
> about Delegats in Jesse Liberty's C# Programming book and, well, I'm
> confused as to the motivation behind delegates. On the surface, they look
> exactly like using interfaces in java, so why have another construct to
> confuse things?

They make things a lot easier than interfaces:

1) You don't need to declare that a type implements them
2) You can make your delegate private
3) You can have the same delegate signature implemented several times
in the same type
4) Multicast delegates act as a very convenient way to implement event
handlers

> I know they work "like function pointers" but the whole reason I went to
> java was to avoid pointers! And before java, I used VB, so pointers are not
> something advantageous to me. And I understand delegates are how .net does
> event driven coding, but why can't interfaces be used to accomplish the
> samething?

They can for the most part - they're just not as convenient.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

RE: motivation behind delegates by Andrew

Andrew
Fri Jan 28 14:05:03 CST 2005

These related articles, though pretty old now, are pretty entertaining to
me....

(must read in order):

http://java.sun.com/docs/white/delegates.html

http://msdn.microsoft.com/vjsharp/productinfo/visualj/visualj6/technical/articles/ge
neral/truth/default.aspx


"Flip" wrote:

> I'm sorry for the newbie question, but I'm a bit confused. I'm reading
> about Delegats in Jesse Liberty's C# Programming book and, well, I'm
> confused as to the motivation behind delegates. On the surface, they look
> exactly like using interfaces in java, so why have another construct to
> confuse things?
>
> I know they work "like function pointers" but the whole reason I went to
> java was to avoid pointers! And before java, I used VB, so pointers are not
> something advantageous to me. And I understand delegates are how .net does
> event driven coding, but why can't interfaces be used to accomplish the
> samething?
>
> Thanks for any advice.
>
>
>