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.
Printable View
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.
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.Quote:
Originally Posted by jmcilhinney
Thanks
Imran Ahmad Mughal