A delegate in .Net is juts like a function pointer in C#.

Discussion in 'General Computer Support' started by VTS, Nov 10, 2010.

  1. VTS

    VTS

    Joined:
    Nov 10, 2010
    Messages:
    1
    The most important property of a function pointer is that the syntax of the function and the pointer to the function must exactly be same. The returntypes and the list of arguments must match exactly.

    Eg:

    If a function looks like: int fact(int)
    Then its function pointer should look like: int *p (int)

    Here, as you may see the return types and the list of arguments of both function and function pointer match exactly.

    When we use delegate then there are 3 stages which we need to follow:

    Declaration: delegate <returntype> delegateName (<list of arguments>)
    Object Creation: delegateName objDelegate = new delegateName(<function to which the delegate points>)
    Invoking: objDelegate(<list of arguments that are to be passed to the function>)

    The main uses of delegate comes in the following circumstances:

    1) When we want to create the controls dynamically, then we cannot create the events for these controls beforehand as these controls are created only on runtime. In that case, if we want to bind these controls with their respective events then we need to use delegate.

    So, delegate is first and foremost used for dynamic binding of controls with their events.

    2) Delegate is also used in multitasking using threading.

    Eg: Suppose we are copying a file from C: drive to D: drive. Then a progress bar would run which would indicate from time to time that how much contents have been copied - like 20% copied, 30% copied. This thing is an example of multiswitching, since here the thread is switching between 2 seperate opertaions. Once it is copying the data from one location to another location and then it is evaluating that how much content has been copied and increasing the progress bar accordingly. But, this switching is happening so fast, that the user gets a feeling as if 2 operations are happenng simultaneously.

    So, in the above case, we may use a thread and make it switch between 2 operations. In this case also the delegate comes into play.
    VTS, Nov 10, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UmV4?=

    Auto switching Wireless Connection Function on Windows CE .NET v4.

    =?Utf-8?B?UmV4?=, Mar 9, 2005, in forum: Wireless Networking
    Replies:
    0
    Views:
    606
    =?Utf-8?B?UmV4?=
    Mar 9, 2005
  2. Cowboy \(Gregory A. Beamer\)

    Take MCSD.NET with VB.NET and C#.NET in the same time?

    Cowboy \(Gregory A. Beamer\), Jan 1, 2004, in forum: MCSD
    Replies:
    1
    Views:
    434
    The Fox
    Jan 1, 2004
  3. qf

    about delegate

    qf, Dec 23, 2004, in forum: MCAD
    Replies:
    1
    Views:
    289
    Xavier
    Dec 28, 2004
  4. yeah

    about delegate

    yeah, Dec 23, 2004, in forum: MCAD
    Replies:
    1
    Views:
    281
  5. Arnnei
    Replies:
    0
    Views:
    626
    Arnnei
    Dec 10, 2009
Loading...

Share This Page