Results 1 to 3 of 3

Thread: Actual advantage of Delegates ??

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    110

    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();
    }

    }

    }
    Anis Bombaywala

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    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.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width