Click to See Complete Forum and Search --> : C# delegate question


GoDaddy
March 1st, 2006, 10:08 PM
Hi,

i've seen some code with delegate in it

for example :


Figure figure = new Figure(10,20,30);
FigureDelegate fx = new FigureDelegate(figure.InvertX);
FigureDelegate fy = new FigureDelegate(figure.InvertY);
FigureDelegate fz = new FigureDelegate(figure.InvertZ);



what is the use if you can just call each one seperatly like normaly? why use delegate if is does the same as calling the fonction.

Maybe that is not a good example to show the use of delegate. Can someone show me a concrete example easy to understand the use of delegate?

Thanks

jmcilhinney
March 1st, 2006, 11:14 PM
One of the most common uses of delegates is to access members of a control from a worker thread. You cannot access members of controls in any thread other than the UI thread. In this case you create a delegate, whcih can cross the thread boundary and invoke a method on the UI thread, thus allowing you to access control members.

hansipet
March 2nd, 2006, 12:28 AM
delegates are also used for callback function and events

Regards
Hansjörg

jhammer
March 2nd, 2006, 11:07 AM
And of course you can call a method asynchronously using BeginInvoke and EndInvoke.