|
-
May 10th, 2004, 05:25 AM
#1
Thread Starter
Lively Member
Actual advantage of Delegates ??
Below is a valid example of a very simple Delegate.
Invocation is done at the line:
sd();
My Question is that whatever happens by calling "sd();"
can also be achieved by calling the "ActualFunction();"
Then WHY are we calling the other way round ??
using System;
namespace SimpleDelegateExample
{
delegate void SimpleDelegate();
class TestDelegate
{
static void ActualFunction()
{
Console.WriteLine("called by delegate..");
}
static void Main1()
{
SimpleDelegate sd = new SimpleDelegate(ActualFunction);
sd();
}
}
}
-
May 10th, 2004, 04:16 PM
#2
Delegates are always needed when you you use multithreaded applications. When you want to notify the control in the original thread, you will always have to use delegates.
-
May 10th, 2004, 05:50 PM
#3
My Question is that whatever happens by calling "sd();"
can also be achieved by calling the "ActualFunction();"
The interesting thing is that in a more complex application you don't know that it's ActualFunction you're calling. It might be MysteriousFunction or SecretFunction. It depends on what gets assigned to the delegate, and that's why they're useful.
If the situation makes it clear that it will always be ActualFunction that is called then you're misusing delegates.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
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
|