Results 1 to 3 of 3

Thread: What is delegate? and Use?

  1. #1

    Thread Starter
    Addicted Member senthilkumartd's Avatar
    Join Date
    Feb 2005
    Posts
    206

    What is delegate? and Use?

    Hi,
    What is called delegate?. What is the usage? Please tell it in simple way. Please don't give big explanation. I already confused with large theoritical explanation. If possible please give one simple example.
    God has been pleased to place as a king or cobbler do the work sincerely

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: What is delegate? and Use?

    OOP is designed to mimic the real world and delegates are no different. I live in Australia and Australia is a member of the UN. If there's a UN meeting then Australia sends a delegate. If there's a ballot then that delegate casts a vote on Australia's behalf, so Australia has voted without actually being there.

    In .NET programming a delegate is an object that contains a reference to a method. You can pass that delegate around form method to property just like any other object. When you invoke the delegate it will execute the method it has a reference to, even if the object that the method is a member of is nowhere nearby.

    Let's say that you had a Country class and you created an instance named Australia. Australia could create a delegate object and provide it a reference to its Vote method. It could then pass that delegate to another object, which might represent the UN. That object could then call the delegate's Invoke method and, even though the Australia object is not present, its Vote method will be executed.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Hyperactive Member ahmad_iam's Avatar
    Join Date
    Jun 2005
    Location
    Pakistan
    Posts
    265

    Lightbulb Re: What is delegate? and Use?

    Quote Originally Posted by jmcilhinney
    OOP is designed to mimic the real world and delegates are no different. I live in Australia and Australia is a member of the UN. If there's a UN meeting then Australia sends a delegate. If there's a ballot then that delegate casts a vote on Australia's behalf, so Australia has voted without actually being there.

    In .NET programming a delegate is an object that contains a reference to a method. You can pass that delegate around form method to property just like any other object. When you invoke the delegate it will execute the method it has a reference to, even if the object that the method is a member of is nowhere nearby.

    Let's say that you had a Country class and you created an instance named Australia. Australia could create a delegate object and provide it a reference to its Vote method. It could then pass that delegate to another object, which might represent the UN. That object could then call the delegate's Invoke method and, even though the Australia object is not present, its Vote method will be executed.
    jmcilhinney, Please provide me the explanation of delegate in code so that the concept become more consolidate.

    Thanks
    Imran Ahmad Mughal
    "Visual Studio .NET 2005/.NET Framework 2.0"

    The eyes are the greatest telescopes, one will ever need to study the universe. Let the heart be the tripod, the mind be the shaft, then let the eyes become the lens of that great telescope of which God gave to us all.

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