|
-
March 1st, 2006, 11:08 PM
#1
C# delegate question
Hi,
i've seen some code with delegate in it
for example :
Code:
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
-
March 2nd, 2006, 12:14 AM
#2
Re: C# delegate question
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.
-
March 2nd, 2006, 01:28 AM
#3
Re: C# delegate question
delegates are also used for callback function and events
Regards
Hansjörg
-
March 2nd, 2006, 12:07 PM
#4
Re: C# delegate question
And of course you can call a method asynchronously using BeginInvoke and EndInvoke.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|